Skip to content

fix(cso): treat untracked nested repos and submodules as snapshot boundaries - #3256

Closed
surlymochan wants to merge 1 commit into
garrytan:mainfrom
surlymochan:fix/cso-nested-repo-snapshot
Closed

surlymochan wants to merge 1 commit into
garrytan:mainfrom
surlymochan:fix/cso-nested-repo-snapshot

Conversation

@surlymochan

Copy link
Copy Markdown
Contributor

Refs #3255 (bug 1).

Problem

gstack-cso start aborts with UNSAFE_PATH: Expected a contained relative path when the audited repo contains an untracked nested Git repository. git ls-files --others lists it as one entry with a trailing slash (inner/), and paths() passes that straight to relativePath(), which rejects the empty segment.

Stripping the slash alone only moves the failure: the capture loop then hands the directory to readStable(), which rejects it as Special or hard-linked source file. A registered submodule already fails at that second step today, since ls-files --cached lists its gitlink as a directory path (sub).

Fix

  • paths() normalizes the trailing slash, the same way the ignored-directory collector in rejectSpecialFiles() already does.
  • In capture(), a directory in Git's inventory is recorded as a repository boundary: one manifest entry with originalHash: 'not-read' and an excluded: transformation (NESTED_REPOSITORY), nothing copied to snapshot/ or readable/. snapshotCoverage() already reports excluded: entries as explicit exclusions, so the omission shows up in the report instead of being silent.
  • assertEntriesStable re-checks each boundary by lstat (dev/ino/mode, not a symlink, still a directory), so a swapped or replaced boundary fails with SNAPSHOT_RACE.

Nested repositories and submodules now behave the same way, and their contents are not audited as part of the outer repo (Git never descends into them either).

Bug 2 (not in this PR)

Passing a larger maxBytes to the history git log -p call is not enough: with ~1.8 MiB of patches, history-status.json still comes back not_assessed with Payload withheld because redaction could not safely locate every secret, because redact() in lib/cso/process.ts scans with maxBytes: MAX_OUTPUT and the redaction engine fails closed above that. Fixing it means raising the redaction ceiling for retained history, which is a policy call I'd rather leave to you.

Verification

  • New tests in test/cso-snapshot-state.test.ts: untracked nested repo, and registered submodule gitlink. Both fail on main (Expected a contained relative path / Special or hard-linked source file: sub) and pass with this change.
  • bun test test/cso-snapshot-state.test.ts: 88 pass, 0 fail.
  • bun run typecheck: clean. bun run typecheck:test: no new diagnostics. bun run format:cso:check: clean.

VERSION/CHANGELOG are left for /ship.

An untracked nested repository makes gstack-cso start fail with
UNSAFE_PATH. Git lists it as one entry with a trailing slash, so
relativePath() rejected the empty segment and aborted the run. A
registered submodule gitlink already failed one step later for the same
reason: it is a directory, and the capture loop only reads regular
files.

Accept the boundary under its own name and record it like a host
dependency tree: one manifest entry, originalHash not-read, an
excluded: transformation that discloses the omission in the report's
snapshot-inputs coverage, no payload copied, and an identity check
during capture so a swapped or symlinked boundary fails closed. Nested
repository contents are never audited with the outer repository because
Git never descends into them.
@trunk-io

trunk-io Bot commented Oct 17, 2026

Copy link
Copy Markdown

Merging to main in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here

@capy-ai

capy-ai Bot commented Oct 19, 2026

Copy link
Copy Markdown
Contributor

Thank you @surlymochan. This was the right fix, and the write-up made it fast to verify. I cherry-picked your commit into #3303 with your authorship kept (c03461a), so it lands under your name. Your two tests fail on main and pass with the change, as you said.

#3303 adds a few things around it:

  • a negative control that swaps a nested repo for another directory mid-capture. It fails if your dev/ino comparison is removed, so that check is now pinned by a test.
  • a control showing that an untracked symlink to a directory is still refused rather than treated as a boundary.
  • the history fix for bug 2. As you pointed out, raising maxBytes only moves the failure into redact(), so the redaction bound stays at 1 MiB. The helper now keeps the newest whole commits that fit, falls back to commit metadata, and records a truncation marker plus partial coverage.

One tweak to your test: the exact entry-list assertion ignores unrelated root files, because a git wrapper on our CI machines writes a log into the fixture repo. I'm closing this in favor of #3303. Thanks again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant