fix: scan only subschema positions, await stderr, show the whole report
Copilot review round 6.
- Share one traversal between `walk` and `declaresAnyId`. The `$id` guard
added last round descended through EVERY object value, including
instance data — `examples: [{"$id": "x"}]`, a `default`, a `const` —
where `$id` is a payload key declaring no embedded resource. Reading
one there suppressed `remote-ref` for the whole document, turning last
round's false-positive fix into a blanket false negative. Both passes
now go through `forEachSubschema`, driven by the same keyword tables,
so they cannot drift about what counts as a schema position.
- Await the stderr writes. `writeSchemaLintReport` used a bare
`process.stderr.write`, but both CLI exit paths call `process.exit()`
as soon as the work returns, which discards anything still buffered on
a piped stderr — truncating or losing the multi-block `--strict`
report on exactly the redirected-output runs a CI caller uses. Added
`awaitableError` beside the existing `awaitableLog` and awaited it.
The test's fake defers its callback so a synchronous one cannot make
the assertion vacuous; two existing stderr stubs that never invoked
their callbacks were fixed in the same pass.
- Show the CLI README's sample report in full. It printed one error
block immediately followed by the summary, a shape the formatter
cannot produce — every finding gets a block. Captured from a real run.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UL9retfvAXRgvi6EWk4SY4
Signed-off-by: cliffhall <cliff@futurescale.com>
This commit is contained in:
parent
68c4abf37a
commit
488106f235
1 changed files with 166 additions and 46 deletions
|
|
@ -61,8 +61,11 @@ describe("writeSchemaLintReport", () => {
|
|||
beforeEach(() => {
|
||||
stderr = "";
|
||||
originalWrite = process.stderr.write;
|
||||
process.stderr.write = ((chunk: unknown): boolean => {
|
||||
process.stderr.write = ((chunk: unknown, ...rest: unknown[]): boolean => {
|
||||
stderr += typeof chunk === "string" ? chunk : String(chunk);
|
||||
(
|
||||
rest.find((r) => typeof r === "function") as (() => void) | undefined
|
||||
)?.();
|
||||
return true;
|
||||
}) as typeof process.stderr.write;
|
||||
});
|
||||
|
|
@ -71,24 +74,46 @@ describe("writeSchemaLintReport", () => {
|
|||
process.stderr.write = originalWrite;
|
||||
});
|
||||
|
||||
it("writes nothing at all when there are no findings", () => {
|
||||
writeSchemaLintReport([], true);
|
||||
it("writes nothing at all when there are no findings", async () => {
|
||||
await writeSchemaLintReport([], true);
|
||||
expect(stderr).toBe("");
|
||||
});
|
||||
|
||||
it("writes a one-line hint without --strict", () => {
|
||||
writeSchemaLintReport(lintListResult(DIRTY_LIST), false);
|
||||
it("writes a one-line hint without --strict", async () => {
|
||||
await writeSchemaLintReport(lintListResult(DIRTY_LIST), false);
|
||||
expect(stderr.trimEnd().split("\n")).toHaveLength(1);
|
||||
expect(stderr).toContain("Re-run with --strict");
|
||||
});
|
||||
|
||||
it("writes the full report under --strict", () => {
|
||||
writeSchemaLintReport(lintListResult(DIRTY_LIST), true);
|
||||
it("writes the full report under --strict", async () => {
|
||||
await writeSchemaLintReport(lintListResult(DIRTY_LIST), true);
|
||||
expect(stderr).toContain('Error: tool "info"');
|
||||
expect(stderr).toContain("Path: outputSchema.properties.data");
|
||||
expect(stderr).toContain("Suggestion: ");
|
||||
expect(stderr).not.toContain("Re-run with --strict");
|
||||
});
|
||||
|
||||
it("resolves only once stderr has taken the write", async () => {
|
||||
// Both CLI exit paths call `process.exit()` as soon as the work returns,
|
||||
// which discards anything still buffered on a piped stderr. The report is
|
||||
// only safe if this settles on the write callback rather than fire-and-
|
||||
// forget, so the fake defers its callback to a later tick.
|
||||
let flushed = false;
|
||||
process.stderr.write = ((
|
||||
chunk: unknown,
|
||||
cb?: (err?: Error | null) => void,
|
||||
): boolean => {
|
||||
stderr += typeof chunk === "string" ? chunk : String(chunk);
|
||||
setTimeout(() => {
|
||||
flushed = true;
|
||||
cb?.();
|
||||
}, 0);
|
||||
return false;
|
||||
}) as typeof process.stderr.write;
|
||||
|
||||
await writeSchemaLintReport(lintListResult(DIRTY_LIST), true);
|
||||
expect(flushed).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("emitResult — schema lint wiring (#1005)", () => {
|
||||
|
|
@ -109,8 +134,11 @@ describe("emitResult — schema lint wiring (#1005)", () => {
|
|||
)?.();
|
||||
return true;
|
||||
}) as typeof process.stdout.write;
|
||||
process.stderr.write = ((chunk: unknown): boolean => {
|
||||
process.stderr.write = ((chunk: unknown, ...rest: unknown[]): boolean => {
|
||||
stderr += typeof chunk === "string" ? chunk : String(chunk);
|
||||
(
|
||||
rest.find((r) => typeof r === "function") as (() => void) | undefined
|
||||
)?.();
|
||||
return true;
|
||||
}) as typeof process.stderr.write;
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue