Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(git-gap): count a path whose ignore status Git cannot read as ignore_status_unknown and name it in git-gap and doctor (#7618)
garrytan66f82f6e4bf8
diff --git a/src/commands/doctor/checks/db-ahead-of-git.ts b/src/commands/doctor/checks/db-ahead-of-git.tsindex 49ad97b69c..5be42328bf 100644--- a/src/commands/doctor/checks/db-ahead-of-git.ts+++ b/src/commands/doctor/checks/db-ahead-of-git.ts@@ -20,7 +20,7 @@ export function gitGapScanTimeoutMs(): number {return Number.isFinite(n) && n > 0 ? n : 10_000;}-type SourceTotals = Pick<GitGapCensus, 'source_id' | 'complete' | 'pages' | 'states' | 'declared' | 'worktree'>;+type SourceTotals = Pick<GitGapCensus, 'source_id' | 'complete' | 'pages' | 'states' | 'declared' | 'worktree' | 'ignore_status_unknown'>;const nonzero = (record: Record<string, number>) => Object.entries(record).filter(([, n]) => n > 0).map(([k, n]) => `${n} ${k}`).join(', ') || 'no pages';@@ -36,8 +36,8 @@ async function runDbAheadOfGit(ctx: DoctorContext): Promise<Check[]> {for (const row of withCheckout) {if (Date.now() >= deadlineAt) { unread.push(row.id); continue; }try {- const { source_id, complete, pages, states, declared, worktree } = await censusGitGap(engine, row.id, { sample: 0, deadlineAt });- sources.push({ source_id, complete, pages, states, declared, worktree });+ const { source_id, complete, pages, states, declared, worktree, ignore_status_unknown } = await censusGitGap(engine, row.id, { sample: 0, deadlineAt });+ sources.push({ source_id, complete, pages, states, declared, worktree, ignore_status_unknown });} catch (error) {errors.push({ source_id: row.id, message: error instanceof Error ? error.message : String(error) });}@@ -45,7 +45,9 @@ async function runDbAheadOfGit(ctx: DoctorContext): Promise<Check[]> {const partial = [...sources.filter(source => !source.complete).map(source => source.source_id), ...unread];const details = { informational: true, sources, partial_sources: partial, errors, sources_without_git_checkout: rows.length - withCheckout.length,timeout_ms: gitGapScanTimeoutMs(), docs: GIT_GAP_DOCS };- const listed = sources.map(source => `${source.source_id}: ${nonzero(source.states)}${source.complete ? '' : ' (partial)'}`);+ const unknownOf = (source: SourceTotals) => Object.values(source.ignore_status_unknown).reduce((sum, n) => sum + n, 0);+ const listed = sources.map(source => `${source.source_id}: ${nonzero(source.states)}${source.complete ? '' : ' (partial)'}`+ + `${unknownOf(source) ? ` (ignore status unknown for ${unknownOf(source)})` : ''}`);const message = withCheckout.length? `Informational, nothing to do: the database compared with the commit at HEAD, per source with a Git checkout.${listed.length ? ` ${listed.join('; ')}.` : ''}`+ `${unread.length ? ` Not reached within the ${details.timeout_ms / 1000}s budget: ${unread.join(', ')}.` : ''}`diff --git a/src/commands/sources-git-gap.ts b/src/commands/sources-git-gap.tsindex c141846898..cdd55c5e9a 100644--- a/src/commands/sources-git-gap.ts+++ b/src/commands/sources-git-gap.ts@@ -63,6 +63,8 @@ export interface GitGapCensus {database_ahead_without_import_record: number;/** git_ahead pages whose row also moved since its last import: both sides changed. */git_ahead_database_also_moved: number;+ /** Pages whose path Git could not say is ignored, by reason (IgnoreUnknownReason); they are classified as if not ignored. */+ ignore_status_unknown: Record<string, number>;/** Pages of a source without a checkout that are not declared. Since G7a such a source is declared `database_only_source`, so this stays 0; kept for readers of the JSON. */not_compared: number;/** Working-tree files of the pages that may have a tracked file, by their raw bytes against HEAD; null without a checkout. */@@ -110,7 +112,7 @@ const zeros = <K extends string>(keys: readonly K[]) => Object.fromEntries(keys.function emptyCensus(sourceId: string, root: string | null, head: HeadTree | null): GitGapCensus {return { status: 'census', source_id: sourceId, checkout: root, head: head?.commit ?? null, complete: true, pages: 0, states: zeros(PAGE_STATES),- declared: zeros(DECLARED_CLASSES), declared_with_head_blob: 0, database_ahead_without_import_record: 0, git_ahead_database_also_moved: 0, not_compared: 0,+ declared: zeros(DECLARED_CLASSES), declared_with_head_blob: 0, database_ahead_without_import_record: 0, git_ahead_database_also_moved: 0, ignore_status_unknown: {}, not_compared: 0,worktree: root ? zeros(WORKTREE_STATES) : null,rows_without_git_home: { facts_unfenced: 0, facts_fence_page_missing: 0, facts_on_pages_without_file: { undeclared: 0, declared: 0 },links: { total: 0, by_link_source: {} }, timeline_on_pages_without_file: { undeclared: 0, declared: 0 } },@@ -187,12 +189,16 @@ async function censusBatch(tx: BrainEngine, batch: Key[], census: GitGapCensus,return { key, path, rel: path ? relative(checkout!.root, path).split(sep).join('/') : null };});if (checkout) {- // A path whose ignore status Git cannot read (one beyond a symlink) is classified as if not ignored: the conversion plan- // discards it as ignore_status_unknown instead of adopting it.+ // A path whose ignore status Git cannot read (one beyond a symlink) is classified as if not ignored and counted under+ // ignore_status_unknown, so the report names it; the conversion plan discards it as ignore_status_unknown instead of adopting it.const status = await ignoredPaths(checkout.root, rows.flatMap(row => row.rel === null ? [] : [row.rel]));if (!status) throw refuse(`Git could not say which paths the checkout at ${checkout.root} ignores, so the declared classes are unknown.`,`Nothing changed. Check that ${checkout.root} is a Git checkout (git -C ${checkout.root} rev-parse HEAD), then rerun gbrain sources git-gap ${batch[0]!.source_id}.`);ctx.policy.ignored = status.ignored;+ for (const { rel } of rows) {+ const reason = rel === null ? undefined : status.unknown.get(rel);+ if (reason) census.ignore_status_unknown[reason] = (census.ignore_status_unknown[reason] ?? 0) + 1;+ }}const noFile = { undeclared: [] as Key[], declared: [] as Key[] };const compare: Array<{ key: Key; path: string; rel: string; blob: TreeBlob; worktree: WorktreeState }> = [];@@ -331,6 +337,8 @@ export function describeGitGap(census: GitGapCensus): string {else if (!census.head) lines.push('The checkout has no commit yet, so no page has a committed file.');lines.push(`Pages: ${counts(census.states)}.`, `Declared database-only: ${counts(census.declared)}${census.declared_with_head_blob ? ` (${census.declared_with_head_blob} still committed at HEAD)` : ''}.`);if (census.database_ahead_without_import_record) lines.push(`${census.database_ahead_without_import_record} database_ahead page(s) have no import record, so the side that moved is unknown.`);+ const unknown = Object.values(census.ignore_status_unknown).reduce((sum, n) => sum + n, 0);+ if (unknown) lines.push(`${unknown} page(s) have a path whose ignore status Git could not read (${counts(census.ignore_status_unknown)}), so whether they are declared database-only is unknown; they are counted above as if not ignored.`);if (census.git_ahead_database_also_moved) lines.push(`${census.git_ahead_database_also_moved} git_ahead page(s) also changed in the database since their last import.`);if (census.worktree) lines.push(`Working tree against HEAD: ${counts(census.worktree)}.`);const rows = census.rows_without_git_home;diff --git a/test/git-gap-census.test.ts b/test/git-gap-census.test.tsindex 313f14b942..3c6f06b07d 100644--- a/test/git-gap-census.test.ts+++ b/test/git-gap-census.test.ts@@ -235,6 +235,28 @@ for (const backend of testBackends()) describe(`git-gap census (git-canonical G1expect(census.sample.find(item => item.slug === 'link/beyond')).toMatchObject({ path: 'link/beyond.md', state: 'undeclared_database_only' });});+ /**+ * Value: protects=a page whose ignore status Git refuses to read is reported as unknown by git-gap and doctor, never as a+ * plain undeclared or worktree count; fails_when=the census drops ignoredPaths' unknown set (the pre-#7618 census refused+ * instead); seam=none (a real check-ignore refusal beyond a symlink); no_claim=timeout and outside-repo reasons.+ */+ test('#7618: a page whose ignore status Git cannot read is counted and named as unknown by git-gap and doctor', async () => {+ const root = tempDir('git-gap-census-unknown-');+ git(root, 'init', '-q');+ await useCheckout(root);+ for (const slug of ['notes/equal', 'link/beyond']) await engine.putPage(slug, { type: 'note', title: slug, compiled_truth: `Body of ${slug}.`, timeline: '' });+ put(root, 'notes/equal.md', await rendered('notes/equal'));+ commitAll(root, 'init');+ mkdirSync(join(root, 'real'));+ symlinkSync('real', join(root, 'link'));+ const census = await censusGitGap(engine, 'default', { sample: 0 });+ expect(census).toMatchObject({ pages: 2, ignore_status_unknown: { symlink: 1 } });+ expect(describeGitGap(census)).toContain('1 page(s) have a path whose ignore status Git could not read (symlink 1)');+ const [check] = await dbAheadOfGitEntry.run({ engine, progress: { heartbeat: () => {} } } as never) as Array<{ message: string; details: any }>;+ expect(check!.details.sources.find((s: { source_id: string }) => s.source_id === 'default')).toMatchObject({ ignore_status_unknown: { symlink: 1 } });+ expect(check!.message).toContain('default: 1 equal, 1 undeclared_database_only (ignore status unknown for 1)');+ });+test('a repository filter, textconv or fsmonitor never runs: HEAD and the working tree are read without them', async () => {const root = tempDir('git-gap-filter-');git(root, 'init', '-q');