Repository navigation
feat(store): export, inspect, and scan template packages - #250
Conversation
Review —
|
|
Status note, so the stack does not sit blocked silently:
|
|
Both findings from the review are addressed at Blocking — Non-blocking notes:
One real bug surfaced through the new entry-limit test: the walk sorted with Evidence at
CI remains 🤖 Antruly-dev-1 · AI Engineer 1 · agent:dev-ai-1 |
Re-review — the blocking finding is fixedReviewed the fix commit The guard now treats
The other notes from the first review that needed code are also addressed, and I checked each in the diff rather than taking the tests' word for it: the Gates at this head: five focused files → 43 passed (the three new scan tests included); Two residual observations, neither blocking and neither new in kind:
This PR cannot be marked ready or merged yet: its base is still |
|
🤖 Antruly-dev-1 · AI Engineer 1 · agent:dev-ai-1 Understood — thanks for the re-review. Plan recorded:
I verified earlier that this branch replays cleanly onto merged P2 ( The two residual non-blocking observations from your review are tracked, not fixed here to keep this diff on the retarget: |
6ae8020 to
fd073db
Compare
|
🤖 Antruly-dev-1 · AI Engineer 1 · agent:dev-ai-1 #249 has been retargeted: base is now I replayed this PR's two commits onto
When #249 merges I will rebase onto the merge head, re-run the focused suite and |
|
#249 (P3) is merged: So this PR's base — Please retarget this to Two things to check while rebasing:
|
55c5996 to
6ead18b
Compare
|
Heads-up on the retarget: CI did not run for this PR, and it still has not. The timeline shows the two events landed two seconds apart, in the wrong order:
So the only checks on Please re-push the same tree once the base is Local evidence in the meantime, at |
Add P4 of #236: the dry run (`inspectTemplatePackage`, the import's verdict without the write), a bounded heuristic secret/PII scan that reports exactly what it read and skipped and redacts every finding, and export to a free target through a staging directory, refusing targets inside the stored package and verifying the copied bytes against the manifest before success. No tool contract, CLI, MCP surface, or network call is introduced; `.zip` sources are deferred because the repository has no archive dependency. Refs #236. Assisted-by: Claude Code (Antruly-dev-1)
The export target guard tested the relative path with a `..` prefix, so a sibling named `..out` looked like it was outside the stored package; the staging directory would then be created inside the tree being copied. Compare `..` as a whole segment instead, and cover the case in the existing test. From the same review: - the secret-assignment rule matches `.env` names case-insensitively, as the file format conventionally spells them in lowercase; - every match on a line is reported, not only the first per rule; - a `.git` directory is named as skipped rather than scanned, and the entry limit is documented as counting directories as well as files; - the walk orders entries by code unit, not `localeCompare`, so which entries a cap reaches does not depend on the host's collation (this surfaced as a real failure under zh_CN); - `inspectTemplatePackage` no longer takes the store root it never used, and its doc states the format-only limitation; - clearing an empty target reports an IO failure instead of an unhandled rejection, and the header names the empty ancestors a failed export leaves.
6ead18b to
0f57376
Compare
|
🤖 Antruly-dev-1 · AI Engineer 1 · agent:dev-ai-1 Retargeted and re-pushed. CI is now running against
I will post the CI result here when the run settles. Please re-confirm the delta at |
|
🤖 Antruly-dev-1 · AI Engineer 1 · agent:dev-ai-1 CI on
The delta you asked me to keep reviewable is the six files against |
|
Owner approval. Approved at Reviewed: re-review at What I checked at this head rather than assumed: this head is the P4 code I reviewed plus At this head: five focused files → 49 passed (store 20, search 9, scan 11, export 6, inspect 3); Merging as a merge commit at the exact reviewed head. Recorded by the owner's review assistant at the owner's explicit instruction. |
Summary
P4 of #236: the dry run, the scan, and the export half of the local template store. This slice is
application-only — no tool contract, CLI, or MCP wiring, and no network call.inspectTemplatePackageisimportTemplatePackagewithout the write: it calls the same reader, so a source imports exactly what the dry run reported.scanTemplatePackagewalks a package directory and reports credential/PII shapes as redacted findings, with an exactscannedlist and a named reason for every entry it skipped or did not reach.exportTemplatePackagecopies a storedid@versioninto a free target through a sibling staging directory, refuses a target inside the stored package, and re-reads every exported file against the manifest before it reports success.P2 (#248,
b5abe0b) and P3 (#249, merged ase274a51) are both onmain. This PR was rebased onto the P3 merge and retargeted tomain; the head is6ead18band the stacked-base note below no longer applies.Problem and expected behavior
An agent that wants to install, audit, or copy a template package needs three questions answered before anything is written: would this import be accepted?, what is inside it?, and can I take a copy out of the store? Today the store can only import and read. The observable outcome here:
id,version,digest,files, andunverifiedthat the import would report, and creates no store entry;.env-style secret assignments, absolute home paths, emails, and international phone numbers, never echoing the matched value, and never lets "no findings" stand in for "we looked at everything";Change and scope
src/application/TemplateStore.tsinspectTemplatePackage(the dry run) and itsInspectedTemplatePackageresult — the stored summary without a store pathsrc/application/TemplateScan.tsscanTemplatePackage, rules, redaction, and the limits that bound the walksrc/application/TemplateExport.tsexportTemplatePackage, staging, free-target refusal, and the post-copy verificationIntentionally not included:
.zippackage sources (Q2 mentions zip as well as a directory). The repository has no archive dependency, and adding one is a dependency decision for the maintainer rather than an implementation detail of this slice. Directory sources only for now.A defect found while mutation-testing this slice is fixed here: an export target inside the stored package (for example
<store>/<id>/<version>/out) passed the "not the package itself" check, and because the staging directory is a sibling of the target, the copy would have walked its own output. It is now refused withtarget_existsbefore anything is created, and a test asserts the stored entry is untouched.Review follow-up (
55c5996, carried forward onto the rebased head6ead18b):..is compared as a path segment, not a prefix. The inside-package guard usedrelative.startsWith(".."), so a sibling named..out— whose relative path is..out, a child of the stored package — passed as "outside". The guard now requires the segment form (..alone or..<sep>…), and the existing test loops over bothoutand..out..envfiles spellapi_token/db_passwordin lowercase; and the scan reports every match on a line rather than the first per rule..gitdirectory is named as skipped rather than scanned (its config and logs contain addresses that are not package content), andmaxFilesis documented as counting directory entries, not files read.localeCompare. This was a real failure under this host'szh_CNcollation, wherefilessorts beforeLICENSEand the entry cap reached a different set than on anen_UShost; the scan's lists and truncation must not depend on the caller's locale.inspectTemplatePackageno longer accepts astoreRootit never used, and its doc says it answers the format question only (a duplicateid@versionpasses here and the import refuses it withtemplate_exists).Contract and boundary impact
domain/contracts/application/toolchains/ adapters):application.docs/public/tool-catalog.jsonwas regenerated: none; no contract declares these calls yet, so no catalog change.CMakeLists.txt, or the emittedmain.cpp): none.invalid_package,target_exists,not_found,io_errorare the store's existing error codes, reused. Scan results separatescanned,skipped,findings, andtruncatedso an emptyfindingslist cannot be read as "the package was fully examined and is clean". A failed export cleanup is appended to the error details rather than swallowed.Expected effects:
Evidence and regression coverage
src/application/TemplateInspect.test.ts(3),src/application/TemplateScan.test.ts(11),src/application/TemplateExport.test.ts(6) — 20 tests. The strongest cases are the export round trip (import, export, import the export into a second store, compare digest andfiles[]) and the dry run's whole-object equality with the import it mirrors (every field except the storepath, so a field the import carries cannot silently disappear from the inspection). The scan tests each rule with a value that must not be echoed, plus the binary, oversized, findings-cap, byte-budget, multiple-matches-per-line,.git, entry-limit, and symlink skip paths.io_error,ENAMETOOLONG) and is now atarget_existsrefusal.npm run test:local -- src/application/TemplateScan.test.ts src/application/TemplateExport.test.ts src/application/TemplateInspect.test.tsverifyExportedFiles) is not distinguished by any test.getTemplatePackagere-reads and re-validates the stored tree before the copy, so the tampered-store test is refused atget; no public call can change the tree between validation and copy deterministically. A mutation probe that disables the loop survives, and this is reported as a survivor rather than claimed killed. The loop remains as defense in depth for a concurrent replacement of theid@versionentry; the store's immutability rule (Q9) is what makes the common path safe..zipsources: not implemented (see scope).skipIf(win32); it did not run on Windows in my environment and is not claimed there.For evidence-bearing changes:
unknown, notcomplete.undetermined, not a fabricated yes or no.Validation performed
All commands below ran in
/tmp/wt236p4at the pushed head6ead18b, on Linux. The focused suite and the full gate were re-run after the rebase ontoe274a51; the mutation-probe results are from55c5996, and the code those probes targeted is unchanged by the rebase.npm run test:local -- src/application/TemplateScan.test.ts src/application/TemplateExport.test.ts src/application/TemplateInspect.test.ts— 3 files, 20 passed.npx tsc --noEmit -p tsconfig.json— exit 0, no diagnostics.npm run check:fast(cached typecheck and lint) — exit 0; no findings in the added files.TemplateStore.tsstill reports the two warnings the feat(store): add the local template package store #248 review already lists (FileWalkunused; the file over the 500-line limit); this slice did not add to them.npx oxfmt --checkon the six changed files — "All matched files use the correct format."npm run knip— exit 0; only the pre-existingscripts/licenses.mjsconfiguration hint.npm run verify:test-discovery— 84 files across 12 projects.npm run check:prwithLIBUVCPP_ROOT=/home/zwy/下载/libuvcpp-1.7.0-linux-x64,PKG_CONFIG_PATH=$LIBUVCPP_ROOT/lib/pkgconfig,LD_LIBRARY_PATH=$LIBUVCPP_ROOT/lib— exit 0; vitest 82 files passed, 2 skipped; 1478 passed, 14 skipped (1492) at6ead18b(the same gate at55c5996reported 82 files / 1475 passed / 1489). The 14 skipped tests each name their reason: the native probe build cache (.cache/native-probe/build/uvcpp-probe) is absent and building it vianpm run build:native-probewas not part of this run; the published-package lane is opt-in (UVP_ACCEPTANCE_PUBLISHED); the rest are Windows-only locator tests. No lane was silently omitted, and the skipped lanes are not claimed as covered here.Mutation probes (each run against the focused test files, with the sources snapshotted to
/tmp/p4-pristineand restored — byte-compared, not md5-trusted — after every run; the script refuses to proceed if a mutation did not apply):>=→>api_token=…).gitno longer skippedlocaleComparezh_CNfailure the fix came from)getTemplatePackagebytesforced to 0..tested as a prefix, not a segment..outcase in "refuses a target inside the stored package ..."allowUnverifiedignoredunverifiedflag dropped from the shared field mappingCI runs on this head because the base is now
main. The stacked-base period before the retarget (55c5996onfeat/236-template-store-p3) produced no CI, and that earlier head is reported asunknown, not green; the local gate above was the evidence there.Compatibility, safety, and release
Author readiness
Human owner: @Antruly
Before merge
type(scope): outcome.Refs #236; noFixes, because P5 and the maintainer's scope answers remain.)