fix(cli): stream JSON results at the shared command boundary
Route ordinary CLI results through the bounded JSON writer after command registration, including managed member inspection. Remove JavaScript-specific output plumbing while preserving filters, envelopes, cancellation, and failure exits. Measure formatted UTF-16 expansion before Incur token counting and return resource_constraint above the runtime string limit, with recovery guidance. Validate output above the real V8 string limit by SHA-256 and exercise the compiled managed provider. Clean-worktree validation: npm run check; 76 focused tests passed, with 2 optional-provider skips; test discovery passed. Fixes #1371.
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
import { writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
|
||||
import { expect } from "vitest";
|
||||
|
||||
import { buildManagedPeFixture } from "../../src/dotnet/ManagedPe.fixture.js";
|
||||
import { createTestTempDirectory } from "../fixtures/temporaryDirectory.js";
|
||||
import { cliTest } from "../support/cli/cliFixture.js";
|
||||
|
||||
cliTest(
|
||||
"managed CLI preserves evidence, filters, envelopes, and bounded token counts",
|
||||
async ({ cli }) => {
|
||||
const root = await createTestTempDirectory("rea-managed-cli-output-");
|
||||
const path = join(root, "fixture.dll");
|
||||
await writeFile(path, buildManagedPeFixture());
|
||||
const argv = ["inspect-managed-members", path, "--json"];
|
||||
const result = await cli.run({ arguments: argv });
|
||||
expect(result.exitCode).toBe(0);
|
||||
expect(result.json).toMatchObject({
|
||||
operation: "inspect_managed_members",
|
||||
provider: { id: "rea-dotnet-static" },
|
||||
subject: { local_path: path },
|
||||
normalized_result: {
|
||||
methods: [expect.objectContaining({ token: expect.any(String) })],
|
||||
},
|
||||
});
|
||||
const filtered = await cli.run({
|
||||
arguments: [...argv, "--filter-output", "operation", "--full-output"],
|
||||
});
|
||||
expect(filtered.exitCode).toBe(0);
|
||||
expect(filtered.json).toMatchObject({
|
||||
ok: true,
|
||||
data: "inspect_managed_members",
|
||||
meta: {
|
||||
command: "inspect-managed-members",
|
||||
duration: expect.stringMatching(/^\d+ms$/u),
|
||||
},
|
||||
});
|
||||
const count = await cli.run({
|
||||
arguments: [...argv, "--filter-output", "operation", "--token-count"],
|
||||
});
|
||||
expect(count.exitCode).toBe(0);
|
||||
expect(count.stdout).toMatch(/^\d+\n$/u);
|
||||
const omittedCount = await cli.run({
|
||||
arguments: [...argv, "--filter-output", "toString", "--token-count"],
|
||||
});
|
||||
expect(omittedCount.exitCode).toBe(0);
|
||||
expect(omittedCount.stdout).toBe("0\n");
|
||||
const jsonl = await cli.run({
|
||||
arguments: [
|
||||
"inspect-managed-members",
|
||||
path,
|
||||
"--format",
|
||||
"jsonl",
|
||||
"--filter-output",
|
||||
"operation",
|
||||
],
|
||||
});
|
||||
expect(jsonl.exitCode).toBe(0);
|
||||
expect(jsonl.json).toBe("inspect_managed_members");
|
||||
},
|
||||
);
|
||||
Reference in New Issue
Block a user