fix: tighten graph freshness follow-up#480
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughRemoves ChangesGraph Freshness Source of Truth and Privacy Contract
Sequence Diagram (high-level flow) sequenceDiagram
participant Generator as generateGraph
participant BuildMeta as buildGraphBuildFreshnessMetadata
participant Git as readGitSnapshot/diffGitFilesBetweenCommits
participant Freshness as analyzeGraphContextFreshness
participant Export as buildContextPackGovernanceReceipt
Generator->>BuildMeta: supply collected source_file list
BuildMeta->>Git: attempt repo snapshot (headSha + dirtyFiles)
Git-->>BuildMeta: return headSha and dirtyFiles
BuildMeta-->>Generator: attach graph_build_freshness to graph
Freshness->>BuildMeta: prefer persisted generated_at/generated_ms
Freshness->>Git: request diffs/snapshot for git strategy
Freshness-->>Export: produce graph_freshness without graph_path
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related issues
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (2)
tests/unit/freshness-surfaces.test.ts (1)
390-575: 💤 Low valueRepeated
analyzeGraphContextFreshnesstype-cast block across the new cases.Each of the five new git-drift tests re-declares the same dynamic-import-plus-type-assertion preamble (lines 391-402, 428-439, 465-476, 502-513, 541-552). Extracting a small
loadAnalyzeGraphContextFreshness()helper would remove the duplication and keep the cases focused on their distinct fixtures/assertions.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/unit/freshness-surfaces.test.ts` around lines 390 - 575, The tests repeat the same dynamic-import and type-assertion for analyzeGraphContextFreshness across multiple cases; extract that logic into a small helper (e.g., loadAnalyzeGraphContextFreshness) that performs the import of '../../src/runtime/freshness.js' and returns the typed analyzeGraphContextFreshness function, then replace the repeated blocks in each test with a call to this helper (referencing analyzeGraphContextFreshness and the helper name) so each test only creates its fixture and assertions.src/shared/git.ts (1)
67-94: 💤 Low valueConsider logging git command failures for debugging.
Both
readGitSnapshotanddiffGitFilesBetweenCommitssilently returnnullor[]when git commands fail. This makes it difficult to diagnose issues like:
- Repository corruption
- Invalid commit SHAs
- Git not installed or not in PATH
- Permission issues
Since these functions are used for freshness detection (which can fall back to mtime/fingerprint strategies), silent failures might be acceptable. However, adding debug-level logging would help troubleshoot freshness-related issues in production.
Also applies to: 96-119
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/shared/git.ts` around lines 67 - 94, Update readGitSnapshot and diffGitFilesBetweenCommits to log git command failures at debug level instead of failing silently: catch the thrown error in each function's try/catch and call the shared logger (or processLogger) with a clear message including the function name (readGitSnapshot / diffGitFilesBetweenCommits), the git command context (e.g., rev-parse or status or diff args) and the error details/stack so developers can diagnose git not found, bad SHAs, permission issues, etc.; keep the current return behavior (null or []) but ensure the debug log includes repoRoot, projectDir/commit IDs and the actual error message.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/shared/git.ts`:
- Around line 40-49: decodeGitPath currently only handles '\"' and '\\' escapes
and fails for C-style escapes and octal sequences from git porcelain output;
update the decodeGitPath function to, when the input is a quoted path, unquote
and scan the inner string interpreting backslash sequences: handle \" and \\ as
before, map \n, \r, \t (and other common C escapes like \b, \f, \v if desired)
to their control characters, and decode octal escapes \NNN (up to three octal
digits) into the corresponding byte/char, returning the fully unescaped string;
alternatively you may switch callers to use git porcelain with -z to avoid
quoted/escaped paths, but if keeping decodeGitPath implement a small stateful
parser in decodeGitPath to replace the current replaceAll-based logic.
In `@src/shared/graph-build-freshness.ts`:
- Around line 25-43: The normalizeSourceFile function currently returns an
absolute path for inputs that escape the project root (in the branch that checks
relativePath === '..' || relativePath.startsWith(`..${sep}`) ||
isAbsolute(relativePath)); change that branch to return an empty string instead
of resolve(trimmed).replaceAll('\\', '/'), so escaped paths are treated like
other invalid/empty results; keep all other behavior (trim, convert separators
with replaceAll, and the checks for empty/'.') the same.
- Around line 49-57: In fileContentFingerprint, the non-file branch currently
embeds the absolute filePath into the hash which makes fingerprints machine- and
location-specific; change the decision to use a portable identifier by replacing
the absolute path with a project-relative or normalized path (or omit the path
entirely) before feeding it to createHash so fingerprints are stable across
machines; locate the non-file branch in fileContentFingerprint (uses statSync,
createHash, and stats.mtimeMs/stats.size) and compute a relativePath (e.g.,
path.relative(projectRoot, filePath) or path.normalize) or drop the path
component, then update the string passed to createHash accordingly.
---
Nitpick comments:
In `@src/shared/git.ts`:
- Around line 67-94: Update readGitSnapshot and diffGitFilesBetweenCommits to
log git command failures at debug level instead of failing silently: catch the
thrown error in each function's try/catch and call the shared logger (or
processLogger) with a clear message including the function name (readGitSnapshot
/ diffGitFilesBetweenCommits), the git command context (e.g., rev-parse or
status or diff args) and the error details/stack so developers can diagnose git
not found, bad SHAs, permission issues, etc.; keep the current return behavior
(null or []) but ensure the debug log includes repoRoot, projectDir/commit IDs
and the actual error message.
In `@tests/unit/freshness-surfaces.test.ts`:
- Around line 390-575: The tests repeat the same dynamic-import and
type-assertion for analyzeGraphContextFreshness across multiple cases; extract
that logic into a small helper (e.g., loadAnalyzeGraphContextFreshness) that
performs the import of '../../src/runtime/freshness.js' and returns the typed
analyzeGraphContextFreshness function, then replace the repeated blocks in each
test with a call to this helper (referencing analyzeGraphContextFreshness and
the helper name) so each test only creates its fixture and assertions.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 508cb940-8d8b-4514-96e6-bba2e7340302
📒 Files selected for processing (16)
README.mddocs/agent-governance.mddocs/concepts/context-packs.mddocs/reference/cli-and-mcp.mdsrc/contracts/context-pack.tssrc/infrastructure/context-pack-command.tssrc/infrastructure/generate.tssrc/pipeline/build.tssrc/pipeline/export.tssrc/runtime/context-pack-governance.tssrc/runtime/freshness.tssrc/shared/git.tssrc/shared/graph-build-freshness.tstests/unit/answer-ready-explain-pack.test.tstests/unit/freshness-surfaces.test.tstests/unit/handoff-command.test.ts
💤 Files with no reviewable changes (5)
- src/runtime/context-pack-governance.ts
- tests/unit/handoff-command.test.ts
- src/infrastructure/context-pack-command.ts
- src/contracts/context-pack.ts
- tests/unit/answer-ready-explain-pack.test.ts
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Summary
Testing
Closes #479
Summary by CodeRabbit
Documentation
New Features
Bug Fixes
Tests