Repository navigation
feat(diagnostics): report a byte entropy profile for one local file #2331
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
519ebaa
feat(diagnostics): report a byte entropy profile for one local file
mvanhorn b82e190
fix(diagnostics): flag zero-size files as not shown empty
mvanhorn b87f511
fix(diagnostics): merge main and preserve entropy boundary failures
morluto 7a67707
fix(mcp): reject unsupported diagnostic summaries before inspection
morluto eccc741
Merge remote-tracking branch 'origin/main' into fix/byte-entropy-profile
morluto a156b1d
fix(ci): repair integrated checks and Hopper test baseline
morluto a2f6136
test(entropy): use shared MCP schema verification after merge
morluto 4df3682
chore: merge current main into PR #2331
morluto f54b2ae
Merge branch 'main' into fix/byte-entropy-profile
morluto 3a794e9
Merge branch 'main' into fix/byte-entropy-profile
mvanhorn 27c6fd9
fix(catalog): list inspect_byte_entropy under its own provider
mvanhorn f7367fc
fix(cli): resolve the byte-entropy path with absoluteCallerPath
mvanhorn 4e6600d
Merge remote-tracking branch 'upstream/main' into fix/byte-entropy-pr…
mvanhorn e3e5891
Merge origin/main into fix/byte-entropy-profile
kaoru0822-kitauji 1eef8d6
fix(diagnostics): retain entropy read cleanup ownership
morluto da99090
docs(diagnostics): explain entropy output capacity
morluto 9be3d92
fix(diagnostics): preserve entropy cancellation outcomes
morluto cc585b5
fix(diagnostics): close the entropy input and warn on large reports
cursoragent 2489602
fix(diagnostics): keep byte-entropy registration mergeable with main
cursoragent 9d37354
fix(diagnostics): register byte entropy with the shared tool options
cursoragent File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
src/application/binaryDiagnostics/ByteEntropyService.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| import { createHash } from "node:crypto"; | ||
| import { writeFile } from "node:fs/promises"; | ||
| import { join } from "node:path"; | ||
| import { expect, it } from "vitest"; | ||
| import { createTestTempDirectory } from "../../../tests/fixtures/temporaryDirectory.js"; | ||
| import { byteEntropySchema } from "../../domain/native/byteEntropy.js"; | ||
| import { ByteEntropyService } from "./ByteEntropyService.js"; | ||
|
|
||
| it("keeps whole-file identity and entropy while selecting unaligned blocks and a partial tail", async () => { | ||
| const root = await createTestTempDirectory("rea-entropy-"); | ||
| const path = join(root, "bytes"); | ||
| const bytes = Buffer.from(Array.from({ length: 1024 }, (_, i) => i % 256)); | ||
| await writeFile(path, bytes); | ||
| const result = await new ByteEntropyService().inspect({ | ||
| path, | ||
| offset: 3, | ||
| length: 513, | ||
| block_size: 256, | ||
| }); | ||
| if (!result.ok) throw result.error; | ||
| const report = byteEntropySchema.parse(result.value.normalized_result); | ||
| expect(report.blocks).toEqual([ | ||
| { offset: 3, length: 256, entropy: 8 }, | ||
| { offset: 259, length: 256, entropy: 8 }, | ||
| { offset: 515, length: 1, entropy: 0 }, | ||
| ]); | ||
| expect(report.file_entropy).toBe(8); | ||
| expect(report.artifact).toEqual({ | ||
| path, | ||
| bytes: 1024, | ||
| sha256: createHash("sha256").update(bytes).digest("hex"), | ||
| }); | ||
| expect(result.value.subject?.digest.sha256).toBe(report.artifact.sha256); | ||
| expect(result.value.confidence).toBe("observed"); | ||
| }); | ||
|
|
||
| it("rejects missing files, non-files and windows beyond EOF, but accepts empty windows", async () => { | ||
| const root = await createTestTempDirectory("rea-entropy-input-"); | ||
| const path = join(root, "empty"); | ||
| await writeFile(path, ""); | ||
| const service = new ByteEntropyService(); | ||
| for (const input of [ | ||
| { path: join(root, "missing") }, | ||
| { path: root }, | ||
| { path, offset: 1 }, | ||
| { path, length: 1 }, | ||
| { path: "relative" }, | ||
| ]) { | ||
| const result = await service.inspect(input); | ||
| expect(result).toMatchObject({ | ||
| ok: false, | ||
| error: { _tag: "AnalysisInputError" }, | ||
| }); | ||
| } | ||
| const result = await service.inspect({ path }); | ||
| if (!result.ok) throw result.error; | ||
| expect(result.value.normalized_result).toMatchObject({ | ||
| blocks: [], | ||
| runs: [], | ||
| file_entropy: 0, | ||
| window: { offset: 0, length: 0 }, | ||
| }); | ||
| expect( | ||
| byteEntropySchema.parse(result.value.normalized_result).limitations, | ||
| ).toContainEqual(expect.stringContaining("reports a size of 0")); | ||
| }); | ||
|
|
||
| it.skipIf(process.platform !== "linux")( | ||
| "marks a generated /proc file that reports size 0 as not shown empty", | ||
| async () => { | ||
| const result = await new ByteEntropyService().inspect({ | ||
| path: "/proc/version", | ||
| }); | ||
| if (!result.ok) throw result.error; | ||
| const report = byteEntropySchema.parse(result.value.normalized_result); | ||
| expect(report.artifact.bytes).toBe(0); | ||
| expect(report.limitations).toContainEqual( | ||
| expect.stringContaining("Linux /proc entries"), | ||
| ); | ||
| }, | ||
| ); | ||
|
|
||
| it("adds no zero-size limitation to a file with content", async () => { | ||
| const root = await createTestTempDirectory("rea-entropy-nonempty-"); | ||
| const path = join(root, "one"); | ||
| await writeFile(path, "x"); | ||
| const result = await new ByteEntropyService().inspect({ path }); | ||
| if (!result.ok) throw result.error; | ||
| expect( | ||
| byteEntropySchema | ||
| .parse(result.value.normalized_result) | ||
| .limitations.join(" "), | ||
| ).not.toContain("reports a size of 0"); | ||
| }); | ||
|
|
||
| it("honors cancellation before and during streaming", async () => { | ||
| const root = await createTestTempDirectory("rea-entropy-cancel-"); | ||
| const path = join(root, "bytes"); | ||
| await writeFile(path, Buffer.alloc(1024 * 1024)); | ||
| const service = new ByteEntropyService(); | ||
| expect( | ||
| await service.inspect({ path }, { signal: AbortSignal.abort() }), | ||
| ).toMatchObject({ ok: false, error: { _tag: "AnalysisCancelledError" } }); | ||
| const controller = new AbortController(); | ||
| const pending = service.inspect( | ||
| { path, block_size: 256 }, | ||
| { signal: controller.signal }, | ||
| ); | ||
| setTimeout(() => controller.abort(), 5); | ||
| expect(await pending).toMatchObject({ | ||
| ok: false, | ||
| error: { _tag: "AnalysisCancelledError" }, | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.