Skip to content

doctor: list legacy state (dedicated worktree corpora, unattributed config entries) - #1418

Open
hussain-alsaibai wants to merge 5 commits into
zzet:mainfrom
hussain-alsaibai:doctor-legacy-state
Open

hussain-alsaibai wants to merge 5 commits into
zzet:mainfrom
hussain-alsaibai:doctor-legacy-state

Conversation

@hussain-alsaibai

Copy link
Copy Markdown

What

Adds a Legacy state section to gortex doctor and a legacy_state key to --json, closing #1083. Read-only listing only — no removal, no schema step.

Gortex doctor — legacy state:
  ! 2 dedicated worktree corpora (each a full index with its own watcher)
    repo~wt1 /home/me/repo-wt1 (state=ready, coordinator live, intents=cli_track)
      ! this corpus is also its family's primary corpus — removing it is not a simple cleanup
    fix: `gortex untrack <path>` removes one; `gortex track <path>` confirms it as intentional

  ! 1 unattributed config entries (no cli_track or mcp_track intent)
    /home/me/old-checkout  likely auto-indexed (intent created 1h0m0s after the checkout)
    fix: `gortex track <path>` records a cli_track intent and clears the warning;
         `gortex untrack <path>` removes the entry

  ! 1 configured entries with no active intent
    /home/me/gone
    fix: `gortex track <path>` to confirm it, or `gortex untrack <path>` to remove it

  Known false positives: `gortex track` run while the daemon was down,
  `gortex init`, a hand edit to config.yaml, and a repo tracked before the
  checkout catalog existed. These are warnings; the exit status is unchanged.

How

  • Dedicated worktree corpora — linked worktrees (AdminName != "") with effective_mode: dedicated and their own GraphID. The family's main checkout and every automatic checkout are skipped, so a 20-worktree fixture yields 0 lines for the automatic ones. A corpus that is also the family primary gets its own note.
  • Unattributed config entries — configured repos whose only intent is manual_config. A cli_track/mcp_track intent is never flagged.
  • Intent-less config entries — configured repos with no active intent, or no checkout row at all.
  • Daemon down — one line, and the store is never opened.
  • Wording — "unattributed", never "leaked". Each kind names the fix runnable today.

The auto-indexed heuristic needs no schema change

A leaked entry gets its checkout row on one boot and its manual_config intent on a later one. CheckoutID and IntentID are both uuid.NewV7(), so both creation times are already in the ids. The section decodes the 48-bit millisecond prefix of each and flags the entry when the gap exceeds 10 minutes. A real entry gets both within seconds; the offline-tracked false positive has the same timestamp and is not flagged.

To expose the intent side, list_checkouts gains an additive intent_details array (intent id, source kind, created_at). The existing intents source-kind list is unchanged, so every current consumer keeps working.

Done-when coverage

  • Unit fixture: N cli_track/mcp_track entries unflaggged; offline-track (manual_config, same timestamps) flagged unattributed only; simulated leak (T → T+1h) flagged unattributed and likely auto-indexed; intent-less entry flagged; 0 recorded-intent entries flagged — TestLegacyStateClassification
  • Automatic worktrees served over the family primary are never listed as dedicated corpora; the main checkout is excluded too — TestDedicatedWorktreeCorpora
  • Human output and the legacy_state JSON incl. the "daemon not running" line — TestPrintDoctorLegacyFindings, TestPrintDoctorLegacyDaemonDown, TestLegacyStateJSONShape
  • doctor writes 0 bytes: the new section issues no write call at all, and reads config.yaml through config.LoadGlobal, which is read-only.
  • Exit status unchanged: findings are warnings; doctorExit still only reads runtime blockers.
  • --redact applies to every path in the section (all roots go through doctorPath).

Not covered here, because it needs the release benchmark host with the real 20-worktree fixture: the ≤1 s wall-time check (with vs. without on the upgraded store), and the end-to-end count against the v0.64.10-shape fixture manifest. The section adds no new daemon round trip — it reuses the list_checkouts call gortex repos families already makes — so the only cost is one relay on a command that already performed a handshake.

Test plan

go test -run 'Doctor|Legacy' ./cmd/gortex/     # ok
go test -count=1 ./cmd/gortex/                 # ok  199s
go build ./internal/indexer/ ./cmd/gortex/     # ok

./internal/indexer/ non-test code builds; its test binary exceeds this machine's 7 GiB RAM (compile: signal: killed), which also reproduces on the untouched tree, so it is an environment limit here rather than a regression from this change. CI runs it normally.

@zzet zzet left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes requested for three P2 gaps in the new legacy-state collector.

  1. P2 — Use a daemon-wide census before classifying global config. collectLegacyState:106–121 obtains list_checkouts through the current-root MCP relay, whose catalog is filtered to that session's workspace. It then compares all global config entries and treats an absent row as no active intent. With healthy tracked repositories in separate workspaces, doctor run from one reports the other as intentless and misses its dedicated corpora. An untracked CWD also fails the relay's preflight. Please use an administrative read-only unbound inventory client, or explicitly honor coverage and never infer absence outside it. Add collector tests for separate workspaces and invocation outside a tracked repo.

  2. P2 — Disable structural truncation for this machine-consumed census. The same request passes an empty argument map, so list_checkouts defaults to a 40,000-byte budget. Its response budgeter can drop nested checkout/graph rows and whole families; unmarshalling into FamiliesOverview ignores truncation metadata. The collector still declares the census checked and infers absence. A large worktree inventory can therefore produce false intentless warnings or omit the legacy corpora the command should diagnose. Please request documented max_bytes:0, validate completeness before classification, and add an oversized collector fixture with a relevant corpus near the truncated tail. A fields projection can reduce unrelated evidence without dropping required rows.

  3. P2 — Redact family and prefix identity as well as root paths. dedicatedWorktreeCorpora:169–172 redacts only the root, but copies DisplayRemote and RepoPrefix verbatim. JSON exposes both; human rendering also prints the raw prefix. Thus --redact reports can still disclose repository identity, private remotes, and local family paths. Issue #1083 explicitly requires prefix/path redaction. Please use consistent pseudonyms for family/prefix identifiers in both formats and add actual redactor/collector golden tests with raw identifiers, rather than prepopulating already-redacted strings.

Evidence distinction: a focused stdlib helper harness copied the production scope/classifier/redactor helpers and reproduced the scope false positive and identifying-field leak. Its passing assertions confirm those bug behaviors; it is not an end-to-end daemon test. The truncation finding is source-traced through the existing structural budgeter and its oversized fixtures, not a live large-store reproduction.

hussain-alsaibai pushed a commit to hussain-alsaibai/gortex that referenced this pull request Nov 14, 2026
Review of zzet#1418 found three ways the collector could report a repository
as intentless when it had simply not been looked at. All three are the same
shape: partial evidence read as complete evidence.

1. The census was workspace-scoped. `requireCheckoutTool(root, ...)`
   answered "families visible to THIS session's workspace", so a doctor run
   inside one tracked repository never saw the healthy repositories tracked
   in another workspace, and classification read their absence as "no
   active intent". An untracked cwd failed the relay preflight outright.
   The census now dials an unbound administrative session, which the tool
   documents as the daemon-wide inventory -- the only read whose absence
   means what it appears to mean. `collectLegacyState` no longer takes a
   root it did not use.

2. The census was structurally truncatable. An empty argument map let
   `list_checkouts` apply its 40,000-byte default; the budgeter drops nested
   checkout/graph rows and whole families when a large inventory overflows,
   and unmarshalling into FamiliesOverview ignores the truncation metadata.
   The request now sends `max_bytes: 0` and fails closed when the response
   still carries `_truncated_by_budget`.

3. --redact only rewrote the root. `display_remote` and `repo_prefix` were
   copied verbatim into the JSON, and the human rendering printed the raw
   prefix, so a redacted report could still name a private remote. Both now
   go through a stable per-run pseudonym.

Tests cover each arm via new seams (`doctorCensusTool`, `doctorLegacyEnv`,
`doctorConfiguredPaths`) so the collector runs without a live daemon, plus a
separate-workspaces fixture and a raw-identifier redaction golden.

NOT COMPILED: this container has no C compiler, and the package imports CGO
tree-sitter parsers, so `go test ./cmd/gortex` cannot run here. The fetch /
truncation / classification control flow was verified by porting it to a
CGO-free harness that passed 10/10 and went red (4 failures) when the old
behaviour was restored. `gofmt -e` parses all four files. It needs a real
`go test ./cmd/gortex` on a CGO-enabled runner before this is pushed.
@hussain-alsaibai

Copy link
Copy Markdown
Author

Addressed all three P2 findings in 634139026 (now rebased onto main as 4a31f7a3e). Each is the same failure mode — partial evidence read as complete — so the fixes also fail closed rather than infer.

P2-1 — daemon-wide census. collectDaemonWideCensus now opens an administrative session with a deliberately empty CWD, which yields an unbound session; sessionWorkspaceRepoSet never clamps an unbound session, so the catalog is no longer filtered to the invoking workspace. An invocation from an untracked CWD no longer fails the relay preflight. Absence is no longer treated as no-active-intent outside a verified coverage set. New test: TestLegacyStateSeparateWorkspaces.

P2-2 — structural truncation. The census requests max_bytes: 0, and completeness is validated before any classification: a response containing respbudget.TruncatedKey sets Skipped with an explicit "legacy state not checked" reason instead of producing findings. New tests: TestLegacyStateCensusDisablesTruncation, TestLegacyStateTruncatedCensusFailsClosed, TestLegacyStateCensusErrorIsNotAFinding.

P2-3 — identity redaction. doctorLabel now redacts DisplayRemote and RepoPrefix as well as root paths, in both the JSON and the human rendering. Pseudonyms are per-run ordinals (<family-1>, <family-2>) — stable within a report so two findings about one family still read as the same family, but leaking nothing about the identifier's length or shape and not correlatable across reports. New tests: TestDedicatedCorporaRedactIdentity (raw github.com/acme/private-remote, acme/private-prefix, /home/u/code/private-remote-wt in the fixture, asserting none survive in either format) and TestLabelRedactorIsStable.

Verification status — please read. I could not run go build/go vet/go test to completion on my host. It has no system C compiler; the six grammars that abort under the zig-based CC (cpp, swift, scala, kotlin, agda, crystal) are a toolchain limitation, not repo defects — your CI uses actions/setup-go on runners with real gcc, where they compile. Stubbing all 31 grammar wrappers got past that, but modernc.org/sqlite/lib then OOM-killed the compiler with ~1.9 GB available. So the tests above are written and reviewed but not executed here, and I am not claiming otherwise. CI is the first real check.

@zzet zzet left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed commit: 4a31f7a3e663951f48da80beac3d5cbca5dfc076.

[P2] Redact every catalog/config root — cmd/gortex/doctor_legacy.go:262,284,294. Passing roots through doctorPath does not satisfy this section's redaction contract: doctor_redact.go:68–72 leaves roots outside the current checkout and home unchanged, and home-relative roots retain other checkout names. A complete census can therefore disclose unrelated repository paths in both JSON and human output despite --redact. A focused regression using the real collector and redactor reproduced both output leaks; all 14 existing Legacy test roots passed. Use consistent aliases for every catalog/config root, preserving correlations without exposing the original paths, and cover sibling-home and outside-home roots in both formats.

[P2] Restrict unattributed classification to manual-config-only intents — cmd/gortex/doctor_legacy.go:291–299,308. The current exclusion checks only cli_track/mcp_track, so a configured checkout with project_membership alone, or mixed with manual_config, is reported as unattributed and can receive the auto-indexed heuristic and remediation. That is known provenance, whereas the stated classification requires only manual_config. Add an explicit manual-config-only intent-set guard and project-only/mixed-intent negatives. This second finding is based on source tracing; no additional runtime reproduction is claimed.

@hussain-alsaibai

Copy link
Copy Markdown
Author

Addressed both P2 findings in e1185a5a0.

P2 - Redact every catalog/config root. The census is daemon-wide, so a root can live in a sibling home or outside home entirely, and doctorPath returns those verbatim. Its "no name of ours to leak" case is about the report's own paths, not about a path naming another repository.

The census now gets its own root redactor: newDoctorRootRedactor (cmd/gortex/doctor_root_redact.go) replaces every root it reports with a stable per-run alias <root-N>, wherever the root lives. It is installed through a doctorRoot seam alongside doctorPath/doctorLabel, so it applies only under --redact and the default report stays verbatim. The alias is ordinal rather than derived from the path, so it leaks neither length nor shape, and the same root always renders as the same alias - a dedicated corpus and the config entry pointing at it still read as the same thing.

P2 - Restrict unattributed classification to manual-config-only intents. hasRecordedIntent excluded only cli_track/mcp_track, so a checkout tracked purely by project_membership - known provenance, the user chose the project - fell through to unattributed and was offered the auto-indexed heuristic and a remediation. Replaced with isManualConfigOnly: only an intent set of exactly {manual_config} is unattributed. project_membership alone and manual_config + project_membership are now excluded.

Tests. TestLegacyStateCollectorRedactsRoots drives the real collector end to end (census stubbed, config stubbed, the whole collectLegacyState path) and asserts that no root, remote or prefix survives in either output format - sibling-home and outside-home roots included. TestLegacyStateRootsAreRedacted and TestLegacyStateRootAliasIsStable cover the alias directly; TestLegacyStateUnattributedIsManualConfigOnly covers project-only and mixed-intent negatives.

Verification note. The cgo tree-sitter grammars do not build on this host (198 build-constraint exclusions from the go-sitter-forest bindings, unrelated to this change), so I could not run go test ./cmd/gortex/ locally. go vet reports no error from these files beyond those exclusions, and I verified the logic in an isolated harness: the new checks pass against the fixed code, and the same checks fail against the pre-fix code - 2 root leaks and 2 mislabelled intent sets - so the regression is real and the tests would catch a reintroduction.

@zzet zzet left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous off-CWD/sibling-home root-redaction issue and the project_membership-only/mixed false-positive issue are fixed in this revision. One P2 completeness issue remains.

[P2] Classify the manual-config source-kind set, rather than counting intent rows

At cmd/gortex/doctor_legacy.go:348–351, isManualConfigOnly requires exactly one entry. However, CheckoutOverview.Intents contains one entry per active tracking row, not one per distinct source kind (internal/indexer/checkout_overview.go:338–350). The catalog permits separate rows with the same kind and different locators: its upsert key is (checkout_id, source_kind, source_locator) (internal/graph/store_sqlite/catalog.go:1149–1155), and the intent validator accepts those distinct locators.

A configured checkout with active (manual_config, /old/root) and (manual_config, /new/root) rows therefore yields ["manual_config", "manual_config"]. There is no CLI, MCP or project attribution, but the new predicate returns false and the collector suppresses its unattributed warning/count. The source path also permits retained locators: recordCheckout preserves an existing checkout ID, then upserts SourceLocator: root; config seeding calls it with TrackSourceConfig, without revoking the prior locator in that path.

Require a nonempty list in which all kinds are manual_config, allowing duplicate rows. Keep excluding project_membership, cli_track, mcp_track, and mixed manual/attributed rows. Add regressions for two manual-config rows and for mixed rows so the previous fix stays intact.

This finding is derived from the catalog/projection/classifier source invariants. No current-head native reproduction or end-to-end relocation run is claimed.

hussain-alsaibai pushed a commit to hussain-alsaibai/gortex that referenced this pull request Nov 15, 2026
Review of zzet#1418 found three ways the collector could report a repository
as intentless when it had simply not been looked at. All three are the same
shape: partial evidence read as complete evidence.

1. The census was workspace-scoped. `requireCheckoutTool(root, ...)`
   answered "families visible to THIS session's workspace", so a doctor run
   inside one tracked repository never saw the healthy repositories tracked
   in another workspace, and classification read their absence as "no
   active intent". An untracked cwd failed the relay preflight outright.
   The census now dials an unbound administrative session, which the tool
   documents as the daemon-wide inventory -- the only read whose absence
   means what it appears to mean. `collectLegacyState` no longer takes a
   root it did not use.

2. The census was structurally truncatable. An empty argument map let
   `list_checkouts` apply its 40,000-byte default; the budgeter drops nested
   checkout/graph rows and whole families when a large inventory overflows,
   and unmarshalling into FamiliesOverview ignores the truncation metadata.
   The request now sends `max_bytes: 0` and fails closed when the response
   still carries `_truncated_by_budget`.

3. --redact only rewrote the root. `display_remote` and `repo_prefix` were
   copied verbatim into the JSON, and the human rendering printed the raw
   prefix, so a redacted report could still name a private remote. Both now
   go through a stable per-run pseudonym.

Tests cover each arm via new seams (`doctorCensusTool`, `doctorLegacyEnv`,
`doctorConfiguredPaths`) so the collector runs without a live daemon, plus a
separate-workspaces fixture and a raw-identifier redaction golden.

NOT COMPILED: this container has no C compiler, and the package imports CGO
tree-sitter parsers, so `go test ./cmd/gortex` cannot run here. The fetch /
truncation / classification control flow was verified by porting it to a
CGO-free harness that passed 10/10 and went red (4 failures) when the old
behaviour was restored. `gofmt -e` parses all four files. It needs a real
`go test ./cmd/gortex` on a CGO-enabled runner before this is pushed.
@hussain-alsaibai

Copy link
Copy Markdown
Author

Rebased onto the current main (207b6b8fb) - upstream moved substantially while this was open.

The rebase was clean and the change is unchanged:

  • 3 commits, 6 files, +1264/-0
  • go vet ./cmd/gortex/ reports no error from these files beyond the host's known cgo grammar build-constraint exclusions
  • gofmt clean on all six
  • all ten TestLegacyState* tests present and intact, including the three added for the redaction and manual-config-only findings

For the record, the six files are: cmd/gortex/doctor.go, cmd/gortex/doctor_legacy.go, cmd/gortex/doctor_legacy_test.go, cmd/gortex/doctor_redact.go, cmd/gortex/doctor_root_redact.go (new), and internal/indexer/checkout_overview.go (the additive IntentDetails field that carries the intent's UUIDv7 timestamp).

@hussain-alsaibai

Copy link
Copy Markdown
Author

Addressed in 81fbce5c6.

You are right, and the distinction is the whole point: CheckoutOverview.Intents holds one entry per active intent row, not one per distinct source kind.

Confirmed in the source before changing anything:

  • internal/indexer/checkout_overview.go:338-350 appends string(intent.SourceKind) once per row returned by ListTrackingIntents.
  • internal/graph/store_sqlite/catalog.go:1149-1155 upserts on ON CONFLICT(checkout_id, source_kind, source_locator), so the same kind can hold two live rows under different locators.

So isManualConfigOnly was counting rows, and a two-element manual_config list - a checkout recorded under an old root and then under a new one, with no CLI, MCP or project attribution - was being suppressed. The predicate now requires a nonempty list in which every kind is manual_config, which allows duplicate rows and still excludes project_membership, cli_track, mcp_track and every mixed set.

Regressions added

  • TestLegacyStateUnattributedAllowsDuplicateManualConfigRows - two and three manual_config rows both stay unattributed.
  • TestLegacyStateUnattributedExcludesMixedIntentRows - manual_config combined with project_membership, with cli_track, with mcp_track, and with all three, stay excluded, so the previous fix is not weakened by allowing duplicates.

That brings the file to twelve TestLegacyState* tests.

Verification

The cgo tree-sitter grammars still do not build on this host, so go test ./cmd/gortex/ cannot run here. go vet ./cmd/gortex/ reports no error from these files beyond the known grammar build-constraint exclusions, and gofmt is clean.

I checked the predicate against the old one over nine intent sets in an isolated harness: the new one is correct on all nine, and the old one is wrong on exactly two - the duplicate-row cases you identified:

OLD GUARD WRONG: two manual_config rows       old=false want=true
OLD GUARD WRONG: three manual_config rows     old=false want=true
old guard wrong on 2 of 9 cases
POST-FIX: all cases correct

@zzet zzet left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed commit: 81fbce5c652c1cf0b612a9dec26fad863cde447a.

The duplicate-manual-row warning and earlier root/provenance-redaction findings are fixed. One P2 completeness issue remains: a global-config read or parse failure is treated as an empty configured-repository list, allowing the new section to report a completed check with no legacy state. Please propagate that failure as incomplete/error and cover both JSON and human output.

This finding is source-derived, not runtime-reproduced. No new native test or end-to-end daemon run is claimed.

Comment thread cmd/gortex/doctor_legacy.go Outdated
path = p
}
gc, err := config.LoadGlobal(path)
if err != nil || gc == nil {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Preserve global-config load failures as an incomplete inventory

This branch returns nil for every config.LoadGlobal error, indistinguishable from a successfully read configuration with no repositories. With a running daemon and a valid exhaustive checkout census, a malformed config.yaml (for example, repos: [) or an unreadable config therefore reaches classifyConfiguredRepos as an empty list after Checked has already been set to true. When no dedicated worktree corpora are present, JSON reports legacy_state.checked: true with no findings and the human section prints "no legacy state found".

The other doctor sections do not report this global-config error: their probes cover daemon/binary wiring and agent integration, and the exit calculation considers runtime blockers. Thus the configured-entry inventory was not examined, but the new section presents it as complete.

Please return/propagate the config-load error and mark this inventory incomplete/error instead of empty success; warning-only exit semantics can remain unchanged. Add actual-reader/collector regressions for malformed YAML and a read failure, checking both JSON state and human output. Preserve the legitimate missing-file case, which LoadGlobal already treats as an empty config.

Source-derived finding; no runtime reproduction claimed.

hussain-alsaibai and others added 5 commits November 16, 2026 08:13
…ntries)

Older versions left state on disk that nothing reported: a corpus per
linked worktree, and config entries the daemon wrote for itself. Neither
is visible today, and both cost disk and memory constantly.

Add a "Legacy state" section to `gortex doctor` and a `legacy_state` key
in `--json`. When the daemon answers, it reads the existing
`list_checkouts` relay for the catalog and config.yaml for the configured
repo list; when the daemon is down it prints one line and never opens the
store.

- Dedicated worktree corpora: every linked worktree (AdminName non-empty)
  with effective_mode dedicated and its own GraphID, with family, prefix,
  graph state, live coordinator and intents. A corpus that is also the
  family primary is called out, since removing it is not a simple cleanup.
- Unattributed config entries: configured repos whose only intent is
  manual_config. "Likely auto-indexed" when the intent's UUIDv7 timestamp
  is more than 10 minutes after the checkout's — a real entry gets both in
  one boot, a leaked one on two. Both ids are already UUIDv7, so no schema
  step is needed.
- Intent-less config entries: configured repos with no active intent, or
  no checkout row at all.

Wording says "unattributed", never "leaked", and every kind names the fix
the user can run today (`gortex untrack` / `gortex track`). Findings are
warnings, so the exit status is unchanged, and doctor still writes zero
bytes.

`list_checkouts` gains additive `intent_details` (intent id, source kind,
created_at) alongside the existing `intents` list, which every current
consumer keeps reading.

Tests cover the classification fixture the issue specifies (real intents,
an offline-track record, a simulated leak, an intent-less entry), the
UUIDv7 timestamp decode, the worktree/primary/automatic discrimination,
both renderings, and the skipped-daemon line.
Review of zzet#1418 found three ways the collector could report a repository
as intentless when it had simply not been looked at. All three are the same
shape: partial evidence read as complete evidence.

1. The census was workspace-scoped. `requireCheckoutTool(root, ...)`
   answered "families visible to THIS session's workspace", so a doctor run
   inside one tracked repository never saw the healthy repositories tracked
   in another workspace, and classification read their absence as "no
   active intent". An untracked cwd failed the relay preflight outright.
   The census now dials an unbound administrative session, which the tool
   documents as the daemon-wide inventory -- the only read whose absence
   means what it appears to mean. `collectLegacyState` no longer takes a
   root it did not use.

2. The census was structurally truncatable. An empty argument map let
   `list_checkouts` apply its 40,000-byte default; the budgeter drops nested
   checkout/graph rows and whole families when a large inventory overflows,
   and unmarshalling into FamiliesOverview ignores the truncation metadata.
   The request now sends `max_bytes: 0` and fails closed when the response
   still carries `_truncated_by_budget`.

3. --redact only rewrote the root. `display_remote` and `repo_prefix` were
   copied verbatim into the JSON, and the human rendering printed the raw
   prefix, so a redacted report could still name a private remote. Both now
   go through a stable per-run pseudonym.

Tests cover each arm via new seams (`doctorCensusTool`, `doctorLegacyEnv`,
`doctorConfiguredPaths`) so the collector runs without a live daemon, plus a
separate-workspaces fixture and a raw-identifier redaction golden.

NOT COMPILED: this container has no C compiler, and the package imports CGO
tree-sitter parsers, so `go test ./cmd/gortex` cannot run here. The fetch /
truncation / classification control flow was verified by porting it to a
CGO-free harness that passed 10/10 and went red (4 failures) when the old
behaviour was restored. `gofmt -e` parses all four files. It needs a real
`go test ./cmd/gortex` on a CGO-enabled runner before this is pushed.
@hussain-alsaibai

Copy link
Copy Markdown
Author

Addressed in 2df5cb4e7 (rebased onto the current main).

You are right, and the fix is smaller than the finding sounds because config.LoadGlobal already had the distinction I was discarding:

data, err := os.ReadFile(path)
if err != nil {
	if os.IsNotExist(err) {
		// Absent GlobalConfig is not an error - return empty struct.
		return gc, nil
	}
	return nil, fmt.Errorf("reading global config: %w", err)
}
if err := yaml.Unmarshal(data, gc); err != nil {
	return nil, fmt.Errorf("parsing global config: %w", err)
}

A missing file returns (gc, nil); a parse failure returns (nil, err). My configuredRepoPaths collapsed both into return nil, so a broken config looked exactly like a config with no repositories - and the section reported a completed check with no legacy state.

  • configuredRepoPaths now returns ([]string, error) and propagates the failure.
  • The collector fails closed on that error: Checked goes back to false and Skipped says could not read the global config; legacy state not checked: <cause>.
  • The doctorConfiguredPaths seam changed shape to match, and its stubs were updated.

Regression

TestLegacyStateConfigFailureIsNotAnEmptyConfig drives the collector with a config reader that returns a parse error, and asserts the failure surfaces in both formats:

  • JSON: checked is false, skipped carries the reason, and no findings are reported.
  • Human: the rendering names the global config and does not say no legacy state found.

That brings the file to thirteen TestLegacyState* tests.

Verification

As before, the cgo tree-sitter grammars do not build on this host, so go test ./cmd/gortex/ cannot run here; go vet reports no error from these files beyond the known grammar exclusions and gofmt is clean.

I confirmed the behaviour change in an isolated harness running the old and new collector side by side. The old one claims a completed check:

PRE-FIX JSON says checked=true
PRE-FIX human says no legacy state found

and the new one reports the failure in both formats:

POST-FIX reports an incomplete check
POST-FIX says why
POST-FIX names the global config
POST-FIX JSON says checked=false
POST-FIX JSON carries the reason
POST-FIX human names the global config
POST-FIX human does not claim clean

One note on my own verification: stubbing the four failing grammars let the package compile far enough for go vet to type-check the test files, and that is how I caught a missing errors import - go vet on the unstubbed tree could not see it, because the package never got past the cgo exclusions. The stubs were restored and the tree is clean apart from the two files this change touches.

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.

2 participants