117 117 await assert.rejects(inspect(["list", "--offset", "-1"], f.ctx), /offset/i);
120 +test("scoped lists skip only valid headers proven outside date and cwd bounds", async (t) => {
121 + const f = fixture(t);
122 + f.add("inside", "inside", [], { timestamp: "2026-09-01T00:00:00Z" });
123 + const before = f.add("before", "before", [], { timestamp: "2026-08-31T23:59:59Z" });
124 + const after = f.add("after", "after", [], { timestamp: "2026-09-03T00:00:00Z" });
125 + const other = f.add("other", "other", [], { cwd: join(f.cwd, "other") });
126 + for (const file of [before, after, other])
127 + writeFileSync(file, `${readFileSync(file, "utf8")}{"MALFORMED_BODY":`);
129 + const scoped = await inspect(
130 + ["list", "--cwd", f.cwd, "--since", "2026-09-01", "--until", "2026-09-02"],
133 + assert.equal(scoped.complete, true);
134 + assert.equal(scoped.scanned, 4);
135 + assert.equal(scoped.parsed, 1);
136 + assert.equal(scoped.skipped, 3);
137 + assert.equal(scoped.errorCount, 0);
138 + assert.equal(scoped.sessions[0].id, "inside");
139 + assert.equal(scoped.scanned, scoped.parsed + scoped.skipped + scoped.errorCount);
141 + const unscoped = await inspect(["list"], f.ctx);
142 + assert.equal(unscoped.complete, false);
143 + assert.equal(unscoped.scanned, 4);
144 + assert.equal(unscoped.parsed, 1);
145 + assert.equal(unscoped.skipped, 0);
146 + assert.equal(unscoped.errorCount, 3);
147 + assert.equal(unscoped.scanned, unscoped.parsed + unscoped.skipped + unscoped.errorCount);
148 + await assert.rejects(inspect(["show", before, "--since", "2026-09-01"], f.ctx), /line 3/);
151 +test("scoped lists retain unknown and in-scope errors before query filtering", async (t) => {
152 + const f = fixture(t);
153 + f.add("name-hit", "wanted by name", [], { timestamp: "2026-09-01T12:00:00Z" });
154 + const broken = f.add("broken", "unrelated", [], { timestamp: "2026-09-01T12:00:00Z" });
155 + writeFileSync(broken, `${readFileSync(broken, "utf8")}{"MALFORMED_BODY":`);
156 + const unknown = f.add("unknown", "unknown", [], { timestamp: "2026-08-01T12:00:00Z" });
162 + timestamp: "2026-08-01T12:00:00Z",
165 + const result = await inspect(["list", "wanted by name", "--since", "2026-09-01"], f.ctx);
166 + assert.equal(result.complete, false);
167 + assert.equal(result.scanned, 3);
168 + assert.equal(result.parsed, 1);
169 + assert.equal(result.skipped, 0);
170 + assert.equal(result.errorCount, 2);
171 + assert.equal(result.sessions[0].id, "name-hit");
172 + assert.match(result.errors.find((error) => error.file === broken).error, /line 3/);
173 + assert.match(result.errors.find((error) => error.file === unknown).error, /version/i);
174 + assert.equal(result.scanned, result.parsed + result.skipped + result.errorCount);
120 177 test("duplicate names and ID prefixes require disambiguation; discovered paths work", async (t) => {
121 178 const f = fixture(t);
122 179 const file = f.add("abc-1", "duplicate");