Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(persistence): one path Git cannot check no longer discards every adoption candidate (#7617)
garrytanc2ff9dbd113d
diff --git a/docs/guides/error-codes.md b/docs/guides/error-codes.mdindex c54608a739..7b111aa268 100644--- a/docs/guides/error-codes.md+++ b/docs/guides/error-codes.md@@ -1685,9 +1685,9 @@ More: [docs/guides/repair.md#ghost-pages](../../docs/guides/repair.md#ghost-page| Meaning | Why | Next step | Who acts · consent | Verify | Exit | Retryable ||---|---|---|---|---|---|---|-| Converting a source to git-canonical would discard database content or cannot place it, so the apply wrote nothing. | gbrain sources canonical --to git applies only when every database row will be in Git or in a declared database-only class afterwards. The preview counts what would be lost or cannot be placed by category (detail lists them): both_moved and held_drift_both, a page Git and the database both changed; deleted_in_git, a page Git deleted that the database edited since; uncommitted_edit, a working-tree edit the adoption would overwrite; ignored_target, a page whose file Git ignores without a declared class; unparseable and unsafe_path, a committed file or path sync cannot read; segmented_page, a segmented page conversion does not adopt yet; export_mismatch, a page whose export does not read back equal; git_overwrites_database, a page version a strict pass would replace that nothing accepted. There is no override. | Relay the categories and their paths (the --dry-run preview lists them) and ask the user how each should be resolved; preview again afterwards. | user | `repeat the read that failed` | 1 | no |+| Converting a source to git-canonical would discard database content or cannot place it, so the apply wrote nothing. | gbrain sources canonical --to git applies only when every database row will be in Git or in a declared database-only class afterwards. The preview counts what would be lost or cannot be placed by category (detail lists them): both_moved and held_drift_both, a page Git and the database both changed; deleted_in_git, a page Git deleted that the database edited since; uncommitted_edit, a working-tree edit the adoption would overwrite; ignored_target, a page whose file Git ignores without a declared class; unparseable and unsafe_path, a committed file or path sync cannot read; segmented_page, a segmented page conversion does not adopt yet; export_mismatch, a page whose export does not read back equal; git_overwrites_database, a page version a strict pass would replace that nothing accepted; ignore_status_unknown, a target whose ignore status Git cannot read (beyond a symlink, outside the checkout, a timed-out check). There is no override. | Relay the categories and their paths (the --dry-run preview lists them) and ask the user how each should be resolved; preview again afterwards. | user | `repeat the read that failed` | 1 | no |-Reasons: `both_moved`, `held_drift_both`, `held_drift_unknown_differs`, `deleted_in_git`, `uncommitted_edit`, `ignored_target`, `unparseable`, `unsafe_path`, `segmented_page`, `export_mismatch`, `git_overwrites_database`.+Reasons: `both_moved`, `held_drift_both`, `held_drift_unknown_differs`, `deleted_in_git`, `uncommitted_edit`, `ignored_target`, `unparseable`, `unsafe_path`, `segmented_page`, `export_mismatch`, `git_overwrites_database`, `ignore_status_unknown`.More: [docs/designs/GIT_CANONICAL_MEMORY.md#conversion](../../docs/designs/GIT_CANONICAL_MEMORY.md#conversion)diff --git a/src/commands/sources-canonical.ts b/src/commands/sources-canonical.tsindex 4ad68071eb..76f6c08971 100644--- a/src/commands/sources-canonical.ts+++ b/src/commands/sources-canonical.ts@@ -39,7 +39,7 @@ const sample = (paths: string[]) => paths.map(path => ` ${path}`);export function describeGitPreview(p: GitConversionPreview): string {const { detail } = p.discard;const causes = [...Object.entries(detail.git_overwrites_database).flatMap(([cls, kinds]) => Object.entries(kinds).map(([kind, n]) => `git_overwrites_database ${cls} on ${kind} ${n}`)),- ...(['uncommitted_edit', 'unparseable', 'export_mismatch'] as const).flatMap(category => Object.entries(detail[category]).map(([key, n]) => `${category} ${key} ${n}`))];+ ...(['uncommitted_edit', 'unparseable', 'export_mismatch', 'ignore_status_unknown'] as const).flatMap(category => Object.entries(detail[category]).map(([key, n]) => `${category} ${key} ${n}`))];const lines = [`Source ${p.source_id}${p.strict ? ' (already git-canonical)' : ''} at ${p.head?.slice(0, 12) ?? 'no commit'}: ${p.pages} live page(s), ${p.equal} equal to HEAD.`,`Adopt (write the database's page to its file and commit it through the door, ${p.adopt.groups} commit(s) of up to ${CONVERSION_GROUP_MAX}): ${p.adopt.count} (${counts(p.adopt.by)}).`, ...sample(p.adopt.sample),`Declared database-only (nothing written, nothing deleted): ${p.declared.count} (${counts(p.declared.by)}).`,diff --git a/src/commands/sources-git-gap.ts b/src/commands/sources-git-gap.tsindex 9fbe83958d..dd1aaaa966 100644--- a/src/commands/sources-git-gap.ts+++ b/src/commands/sources-git-gap.ts@@ -185,10 +185,12 @@ async function censusBatch(tx: BrainEngine, batch: Key[], census: GitGapCensus,return { key, path, rel: path ? relative(checkout!.root, path).split(sep).join('/') : null };});if (checkout) {- const ignored = await ignoredPaths(checkout.root, rows.flatMap(row => row.rel === null ? [] : [row.rel]));- if (!ignored) throw refuse(`Git could not say which paths the checkout at ${checkout.root} ignores, so the declared classes are unknown.`,+ // 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.+ 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 = ignored;+ ctx.policy.ignored = status.ignored;}const noFile = { undeclared: [] as Key[], declared: [] as Key[] };const compare: Array<{ key: Key; path: string; rel: string; blob: TreeBlob; worktree: WorktreeState }> = [];diff --git a/src/core/error-registry.ts b/src/core/error-registry.tsindex abdc64909b..2dc64e9dba 100644--- a/src/core/error-registry.ts+++ b/src/core/error-registry.ts@@ -332,7 +332,7 @@ export const CODES = {git_target_unsafe: { class: 'caller', summary: "Git cannot identify the existing canonical file by its native spelling." },git_unavailable: { class: 'retryable', summary: "A git command did not complete." },git_object_missing: { class: 'caller', summary: "A committed file's Git object is missing from the checkout and its working-tree copy differs or is gone, so managed sync holds that file alone.", why: "An interrupted gc, a partial clone without its promisor remote or disk corruption can drop an object a commit still names. Sync imports the working-tree bytes when they hash to the committed blob id; otherwise it imports nothing from a guess, and the rest of the source keeps syncing.", docs: 'docs/guides/write-refusals.md#git_object_missing', suggestion: 'Run git fsck in the checkout to see what is missing, restore it with git fetch (a partial or shallow clone) or from a backup, then sync again; every sync re-tests the hold.' },- git_conversion_blocked: { class: 'consent', actor: 'user', summary: "Converting a source to git-canonical would discard database content or cannot place it, so the apply wrote nothing.", reasons: ['both_moved', 'held_drift_both', 'held_drift_unknown_differs', 'deleted_in_git', 'uncommitted_edit', 'ignored_target', 'unparseable', 'unsafe_path', 'segmented_page', 'export_mismatch', 'git_overwrites_database'], why: "gbrain sources canonical --to git applies only when every database row will be in Git or in a declared database-only class afterwards. The preview counts what would be lost or cannot be placed by category (detail lists them): both_moved and held_drift_both, a page Git and the database both changed; deleted_in_git, a page Git deleted that the database edited since; uncommitted_edit, a working-tree edit the adoption would overwrite; ignored_target, a page whose file Git ignores without a declared class; unparseable and unsafe_path, a committed file or path sync cannot read; segmented_page, a segmented page conversion does not adopt yet; export_mismatch, a page whose export does not read back equal; git_overwrites_database, a page version a strict pass would replace that nothing accepted. There is no override.", docs: 'docs/designs/GIT_CANONICAL_MEMORY.md#conversion', suggestion: 'Relay the categories and their paths (the --dry-run preview lists them) and ask the user how each should be resolved; preview again afterwards.' },+ git_conversion_blocked: { class: 'consent', actor: 'user', summary: "Converting a source to git-canonical would discard database content or cannot place it, so the apply wrote nothing.", reasons: ['both_moved', 'held_drift_both', 'held_drift_unknown_differs', 'deleted_in_git', 'uncommitted_edit', 'ignored_target', 'unparseable', 'unsafe_path', 'segmented_page', 'export_mismatch', 'git_overwrites_database', 'ignore_status_unknown'], why: "gbrain sources canonical --to git applies only when every database row will be in Git or in a declared database-only class afterwards. The preview counts what would be lost or cannot be placed by category (detail lists them): both_moved and held_drift_both, a page Git and the database both changed; deleted_in_git, a page Git deleted that the database edited since; uncommitted_edit, a working-tree edit the adoption would overwrite; ignored_target, a page whose file Git ignores without a declared class; unparseable and unsafe_path, a committed file or path sync cannot read; segmented_page, a segmented page conversion does not adopt yet; export_mismatch, a page whose export does not read back equal; git_overwrites_database, a page version a strict pass would replace that nothing accepted; ignore_status_unknown, a target whose ignore status Git cannot read (beyond a symlink, outside the checkout, a timed-out check). There is no override.", docs: 'docs/designs/GIT_CANONICAL_MEMORY.md#conversion', suggestion: 'Relay the categories and their paths (the --dry-run preview lists them) and ask the user how each should be resolved; preview again afterwards.' },git_conversion_incomplete: { class: 'retryable', summary: "A git-canonical conversion stopped because its strict pass did not finish, or finished with work left after the flag was set.", why: "The conversion runs a full strict-equivalent pass before it sets canonical: git, and one genuine strict pass after. A pass that ends partial, blocked or deferred stops the conversion where it is: before the flag the source stays as it was, after it the source stays strict (Git wins) and the plan lists what is left.", docs: 'docs/designs/GIT_CANONICAL_MEMORY.md#conversion', suggestion: 'Wait until gbrain sync status --source <id> --json shows the source idle, then preview again with gbrain sources canonical <id> --to git --dry-run and apply the new hash.' },git_home_required: { class: 'caller', summary: "A git-canonical source would store content in the database without a file in Git; nothing was written.", reasons: ['no_file_form', 'declared_target', 'facts_lane'], why: "On a source with canonical: git, page content reaches the database only after Git commits its file. The declared database-only classes (private, alias-private and lineage-private pages, storage.db_only directories, never-filed derive-phase pages, paths Git ignores, detached pages and origin twins) are the only exceptions. no_file_form: the write has no file and is in no declared class; declared_target: a publication would commit a file for a declared page; facts_lane: a writer with no file form yet.", docs: 'docs/guides/write-refusals.md#git_home_required', suggestion: 'Ask the user which git home to configure (a path Git tracks, or a storage.db_only directory in gbrain.yml), then submit the write again with a new request_id.' },git_private_commit_refused: { class: 'caller', summary: "A git-canonical source refused to commit the file of a private, alias-private or lineage-private page; nothing was written and HEAD is unchanged.", reasons: ['private', 'alias_private', 'lineage_private'], why: "Private pages of a source with canonical: git are database-only: their bytes never enter Git history. A page turning private is published as the door commit that removes its file, never as a commit of its bytes.", docs: 'docs/guides/write-refusals.md#git_private_commit_refused', suggestion: 'The page stays database-only. Write it through put_page (which publishes a private page without a file), or remove visibility: private if it belongs in Git, then submit again with a new request_id.' },diff --git a/src/core/persistence/git-conversion.ts b/src/core/persistence/git-conversion.tsindex f14eba6c95..79b6841a6a 100644--- a/src/core/persistence/git-conversion.ts+++ b/src/core/persistence/git-conversion.ts@@ -78,7 +78,7 @@ export const GIT_WINS_REASONS = ['git_ahead', 'deleted_by_commit', 'held_deletioexport type GitWinsReason = typeof GIT_WINS_REASONS[number];/** Database content the apply would discard or cannot place, by why: each must be zero before the apply runs. */export const DISCARD_CATEGORIES = ['both_moved', 'held_drift_both', 'held_drift_unknown_differs', 'deleted_in_git', 'uncommitted_edit', 'ignored_target', 'unparseable', 'unsafe_path',- 'segmented_page', 'export_mismatch', 'git_overwrites_database'] as const;+ 'segmented_page', 'export_mismatch', 'git_overwrites_database', 'ignore_status_unknown'] as const;export type DiscardCategory = typeof DISCARD_CATEGORIES[number];/** A private, alias-private or lineage-private page whose row still records a file: committed at HEAD, or absent from it. */export const WITHHOLD_KINDS = ['file_committed', 'file_absent'] as const;@@ -89,13 +89,15 @@ interface Counted<K extends string> { count: number; by: Record<K, number>; samp* Counts behind some discard categories (outside the preview hash). git_overwrites_database: the class the path has on a* source that is not strict (with its sub, side or state), then the page's kind (`declared:<class>`, `live`, or* `tombstone_or_none`); uncommitted_edit: the working-tree state; unparseable: why the committed file cannot be read;- * export_mismatch: each field the page's export reads back different (`unparseable:<reason>` when it does not parse).+ * export_mismatch: each field the page's export reads back different (`unparseable:<reason>` when it does not parse);+ * ignore_status_unknown: why Git could not say whether the target is ignored (IgnoreUnknownReason).*/export interface DiscardDetail {git_overwrites_database: Record<string, Record<string, number>>;uncommitted_edit: Record<string, number>;unparseable: Record<string, number>;export_mismatch: Record<string, number>;+ ignore_status_unknown: Record<string, number>;}/** `disk`: sha256 of the working-tree bytes the preview saw (HEAD's or the export's), null when the file was absent. */export interface AdoptItem { id: string; source_id: string; slug: string; revision: string | null; path: string; state: AdoptState; disk: string | null }@@ -136,7 +138,7 @@ export interface GitConversionPlan { preview: GitConversionPreview; context: Manconst counted = <K extends string>(keys: readonly K[]): Counted<K> => ({ count: 0, by: Object.fromEntries(keys.map(key => [key, 0])) as Record<K, number>, sample: [] });const bump = (into: Record<string, number>, key: string) => { into[key] = (into[key] ?? 0) + 1; };-const emptyDiscard = () => ({ ...counted(DISCARD_CATEGORIES), detail: { git_overwrites_database: {}, uncommitted_edit: {}, unparseable: {}, export_mismatch: {} } as DiscardDetail });+const emptyDiscard = () => ({ ...counted(DISCARD_CATEGORIES), detail: { git_overwrites_database: {}, uncommitted_edit: {}, unparseable: {}, export_mismatch: {}, ignore_status_unknown: {} } as DiscardDetail });function tally<K extends string>(into: Counted<K>, key: K, path: string): void {into.count++;into.by[key] = (into.by[key] ?? 0) + 1;@@ -250,7 +252,9 @@ export async function planGitConversion(engine: BrainEngine, sourceId: string):preview.withhold.groups = Math.ceil(withhold.filter(item => item.kind === 'file_committed').length / CONVERSION_GROUP_MAX);preview.remaining = preview.adopt.count + preview.withhold.count + preview.git_wins.count + preview.holds.count + preview.parked_effects.retry + preview.discard.count;preview.preview_hash = previewHash({ source: sourceId, incarnation, to: 'git', strict: preview.strict, head: preview.head, states: census.states, declared: census.declared,- adopt: adopt.map(item => [item.id, item.revision, item.path, item.state, item.disk]), git_wins: [...accepted].sort(), discard: preview.discard.by,+ adopt: adopt.map(item => [item.id, item.revision, item.path, item.state, item.disk]), git_wins: [...accepted].sort(),+ // ignore_status_unknown is bound only when present, so the hash of a plan with no such path is the one earlier releases gave.+ discard: preview.discard.by.ignore_status_unknown ? preview.discard.by : { ...preview.discard.by, ignore_status_unknown: undefined },// Bound only when present, so the hash of a plan with nothing to withhold is the one earlier releases gave.withhold: withhold.length ? withhold.map(item => [item.id, item.revision, item.path, item.kind, item.disk]) : undefined,holds: holds.map(hold => [hold.path, hold.code, hold.side, hold.observed_at]), parked: parked.map(item => [item.effect, item.action, item.codes]), index: preview.index });@@ -295,8 +299,9 @@ class ExportChecks {async function planAdoption(engine: BrainEngine, sourceId: string, root: string, candidates: Array<{ page: GitGapPage; state: AdoptState }>, exported: ExportChecks,preview: GitConversionPreview, adopt: AdoptItem[], discard: (category: DiscardCategory, path: string) => void): Promise<void> {if (!candidates.length) return;- const ignored = await ignoredPaths(root, candidates.map(({ page }) => page.path!));- const unread = candidates.map(({ page }) => page).filter(page => ignored && !ignored.has(page.path!) && !page.segmented && !exported.get(page.id));+ const status = await ignoredPaths(root, candidates.map(({ page }) => page.path!))+ ?? { ignored: new Set<string>(), unknown: new Map(candidates.map(({ page }) => [page.path!, 'git_error' as const])) };+ const unread = candidates.map(({ page }) => page).filter(page => !status.ignored.has(page.path!) && !status.unknown.has(page.path!) && !page.segmented && !exported.get(page.id));const withdrawals = unread.length ? await readExportWithdrawals(engine, sourceId) : [];for (let start = 0; start < unread.length; start += ADOPTION_BATCH) {const batch = unread.slice(start, start + ADOPTION_BATCH);@@ -308,9 +313,11 @@ async function planAdoption(engine: BrainEngine, sourceId: string, root: string,}for (const { page, state } of candidates) {const path = page.path!;- // Fail-closed fallback: an ignored path with no file is already declared git_ignored by the census, and Git commits a- // tracked file whatever its ignore rules say, so this fires only when reading the ignore rules fails (ignored is null).- if (!ignored || ignored.has(path)) { discard('ignored_target', path); continue; }+ // A target Git cannot check (beyond a symlink, outside the checkout, a timed-out check) is never written; the census+ // declares an ignored path with no file git_ignored, so ignored_target is a path whose rules changed since it read them.+ const unknown = status.unknown.get(path);+ if (unknown) { discard('ignore_status_unknown', path); bump(preview.discard.detail.ignore_status_unknown, unknown); continue; }+ if (status.ignored.has(path)) { discard('ignored_target', path); continue; }if (page.segmented) { discard('segmented_page', path); continue; }const check = exported.get(page.id)!;const { readBack } = check;diff --git a/src/core/persistence/git-gap.ts b/src/core/persistence/git-gap.tsindex c1157aa323..6e84ecc167 100644--- a/src/core/persistence/git-gap.ts+++ b/src/core/persistence/git-gap.ts@@ -9,6 +9,7 @@*/import { createHash } from 'node:crypto';import { createReadStream, lstatSync, realpathSync } from 'node:fs';+import { join, posix } from 'node:path';import type { BrainEngine } from '../engine.ts';import { hardenedGitStream, hardenedGitSync, NulRecordSplitter } from '../hardened-git.ts';import { exportBodyLedger, segmentedExportHead, segmentedExportMarkdown, type ExportSnapshot, type ExportWithdrawal } from '../export-snapshot.ts';@@ -58,20 +59,60 @@ export function declaredDatabaseOnly(page: { slug: string; type?: string | null;return null;}+/** Why Git could not say whether a path is ignored: a parent directory is a symlink, the path leaves the checkout, the check timed out, or Git refused it otherwise. */+export const IGNORE_UNKNOWN_REASONS = ['symlink', 'outside_repo', 'timeout', 'git_error'] as const;+export type IgnoreUnknownReason = typeof IGNORE_UNKNOWN_REASONS[number];+export interface IgnoreStatus { ignored: Set<string>; unknown: Map<string, IgnoreUnknownReason> }+const IGNORE_CHUNK = 1_000;+/**- * The paths among `relativePaths` (relative to `root`) that the checkout's ignore rules exclude, read with filter-free- * `git check-ignore -z --stdin`; tracked files are never reported (Git commits them whatever the rules say). Exit 1- * means none matched. Null when Git could not answer, so a caller never reads a failed check as "nothing ignored".+ * Which of `relativePaths` (relative to `root`) the checkout's ignore rules exclude, read with filter-free+ * `git check-ignore -z --stdin`; tracked files are never reported (Git commits them whatever the rules say). Git refuses a+ * whole input for one path it cannot check (one beyond a symlink, one outside the repository), so the paths are checked+ * IGNORE_CHUNK at a time and a refused chunk is bisected down to the paths Git refuses: those, and every path of a chunk+ * that timed out, are `unknown`. Null when Git cannot answer at all (it refuses an empty input too), so a caller never+ * reads a failed check as "nothing ignored".*/-export async function ignoredPaths(root: string, relativePaths: string[]): Promise<Set<string> | null> {- const ignored = new Set<string>();- if (!relativePaths.length) return ignored;+export async function ignoredPaths(root: string, relativePaths: string[]): Promise<IgnoreStatus | null> {+ const status: IgnoreStatus = { ignored: new Set(), unknown: new Map() };+ let answers: boolean | undefined;+ const settle = async (paths: string[]): Promise<boolean> => {+ const answer = await checkIgnore(root, paths);+ if (answer === 'timeout') { for (const path of paths) status.unknown.set(path, 'timeout'); return true; }+ if (answer) { for (const path of answer) status.ignored.add(path); return true; }+ answers ??= Array.isArray(await checkIgnore(root, []));+ if (!answers) return false;+ if (paths.length === 1) { status.unknown.set(paths[0]!, ignoreRefusal(root, paths[0]!)); return true; }+ const half = Math.ceil(paths.length / 2);+ return await settle(paths.slice(0, half)) && await settle(paths.slice(half));+ };+ for (let start = 0; start < relativePaths.length; start += IGNORE_CHUNK) {+ if (!await settle(relativePaths.slice(start, start + IGNORE_CHUNK))) return null;+ }+ return status;+}++/** One `git check-ignore` call: the ignored paths among `paths` (exit 1 means none), 'timeout', or null when Git refused it. */+async function checkIgnore(root: string, paths: string[]): Promise<string[] | 'timeout' | null> {+ const ignored: string[] = [];const splitter = new NulRecordSplitter();const result = await hardenedGitStream(root, ['check-ignore', '-z', '--stdin'], {- stdin: relativePaths.map(path => path + '\0'), timeoutMs: 120_000, maxBytes: 64 * 1024 * 1024,- onChunk: chunk => { for (const record of splitter.push(chunk)) ignored.add(record.toString('utf8')); } });+ stdin: paths.map(path => path + '\0'), timeoutMs: 120_000, maxBytes: 64 * 1024 * 1024,+ onChunk: chunk => { for (const record of splitter.push(chunk)) ignored.push(record.toString('utf8')); } });if (result.ok) return result.endsWithNul || result.bytes === 0 ? ignored : null;- return result.reason === 'exit' && result.status === 1 && ignored.size === 0 ? ignored : null;+ if (result.reason === 'timeout') return 'timeout';+ return result.reason === 'exit' && result.status === 1 && ignored.length === 0 ? ignored : null;+}++/** Why Git refused one path it can otherwise answer for. */+function ignoreRefusal(root: string, path: string): IgnoreUnknownReason {+ const normal = posix.normalize(path);+ if (posix.isAbsolute(normal) || normal === '..' || normal.startsWith('../')) return 'outside_repo';+ const parts = normal.split('/');+ for (let depth = 1; depth < parts.length; depth++) {+ try { if (lstatSync(join(root, ...parts.slice(0, depth))).isSymbolicLink()) return 'symlink'; } catch { break; }+ }+ return 'git_error';}/** Why a committed file cannot be compared: a symlink (or another non-regular mode), bytes that are not UTF-8, or frontmatter that does not parse. */diff --git a/test/git-canonical-conversion-g8a.test.ts b/test/git-canonical-conversion-g8a.test.tsindex 3349fb59f1..39701ddaec 100644--- a/test/git-canonical-conversion-g8a.test.ts+++ b/test/git-canonical-conversion-g8a.test.ts@@ -359,6 +359,20 @@ for (const backend of testBackends()) describe(`[${backend}] G8a: sources canoniexpect(reads).toBeLessThanOrEqual(2 * (Math.ceil(2 * WIDE / 256) + Math.ceil(WIDE / ADOPTION_BATCH)));}, { databaseUrl, setup: wideSetup }), 300_000);+ test('#7618: a target whose ignore status Git cannot read is discarded on its own, and every other candidate adopts', () => managedBrain(async brain => {+ const { engine, root } = brain;+ expect((await performManagedSync(engine, OPTS)).status).toBe('first_sync');+ mkdirSync(join(root, 'real'));+ symlinkSync('real', join(root, 'link'));+ await engine.transaction(tx => withCoordinatedWrite(tx, ['default'], () => tx.executeRaw(`INSERT INTO pages(source_id,slug,type,title,compiled_truth,timeline,frontmatter)+ SELECT 'default',s,'concept',s,'Only in the database.','',jsonb_build_object('type','concept','title',s)+ FROM (SELECT CASE WHEN n=150 THEN 'link/beyond' ELSE 'dbonly/p'||lpad(n::text,3,'0') END AS s FROM generate_series(0,$1::int - 1) n) pages`, [WIDE]), TEST_WRITE_ATTRIBUTION));+ const { preview } = await planGitConversion(engine, 'default');+ expect(preview.adopt).toMatchObject({ count: WIDE - 1, by: { undeclared_database_only: WIDE - 1 } });+ expect(preview.discard).toMatchObject({ count: 1, by: { ignore_status_unknown: 1, ignored_target: 0 }, sample: ['link/beyond.md'], detail: { ignore_status_unknown: { symlink: 1 } } });+ expect(describeGitPreview(preview)).toContain('ignore_status_unknown symlink 1');+ }, { databaseUrl, setup }), 300_000);+test('#7618: a hold at a declared page\'s path is judged by the strict verdict, so a page Git would overwrite is a discard', () => managedBrain(async brain => {const { engine, root } = brain;await heldDeclaredDrift(brain);diff --git a/test/git-gap-census.test.ts b/test/git-gap-census.test.tsindex 9de1670eb2..313f14b942 100644--- a/test/git-gap-census.test.ts+++ b/test/git-gap-census.test.ts@@ -1,6 +1,6 @@import { afterAll, beforeAll, beforeEach, describe, expect, test } from 'bun:test';import { execFileSync } from 'node:child_process';-import { existsSync, mkdirSync, mkdtempSync, realpathSync, rmSync, unlinkSync, writeFileSync } from 'node:fs';+import { existsSync, mkdirSync, mkdtempSync, realpathSync, rmSync, symlinkSync, unlinkSync, writeFileSync } from 'node:fs';import { tmpdir } from 'node:os';import { dirname, join } from 'node:path';import { randomUUID } from 'node:crypto';@@ -141,8 +141,23 @@ for (const backend of testBackends()) describe(`git-gap census (git-canonical G1put(root, 'images/tracked.md', 'x');git(root, 'add', '-f', '.gitignore', 'images/tracked.md');git(root, 'commit', '-qm', 'init');- expect(await ignoredPaths(root, ['images/a.md', 'images/tracked.md', 'notes/b.md'])).toEqual(new Set(['images/a.md']));- expect(await ignoredPaths(root, ['notes/b.md'])).toEqual(new Set());+ expect(await ignoredPaths(root, ['images/a.md', 'images/tracked.md', 'notes/b.md'])).toEqual({ ignored: new Set(['images/a.md']), unknown: new Map() });+ expect(await ignoredPaths(root, ['notes/b.md'])).toEqual({ ignored: new Set(), unknown: new Map() });+ });++ test('#7618: a path Git refuses to check is unknown on its own, and every other path in the input is still answered', async () => {+ const root = tempDir('git-gap-ignore-poison-');+ git(root, 'init', '-q');+ put(root, '.gitignore', 'images/\n');+ mkdirSync(join(root, 'real'));+ symlinkSync('real', join(root, 'link'));+ const paths = Array.from({ length: 2_500 }, (_, i) => i % 100 ? `notes/n${i}.md` : `images/i${i}.md`);+ paths.splice(1_500, 0, 'link/x.md');+ paths.splice(10, 0, '../outside.md');+ const status = await ignoredPaths(root, paths);+ expect(status?.ignored).toEqual(new Set(Array.from({ length: 25 }, (_, i) => `images/i${i * 100}.md`)));+ expect(status?.unknown).toEqual(new Map([['../outside.md', 'outside_repo'], ['link/x.md', 'symlink']]));+ expect(await ignoredPaths(tempDir('git-gap-not-a-checkout-'), ['notes/a.md'])).toBeNull();});test('the census puts every page in one state, compares with HEAD and reports the working tree separately', async () => {@@ -206,6 +221,20 @@ for (const backend of testBackends()) describe(`git-gap census (git-canonical G1expect((await censusGitGap(engine, 'default', { sample: 0 })).declared.mirror_source).toBe(13);}, 120000);+ test('#7618: a batch with a page beyond a symlink is classified, not refused', async () => {+ const root = tempDir('git-gap-census-symlink-');+ git(root, 'init', '-q');+ await useCheckout(root);+ for (const slug of ['notes/equal', 'notes/missing', '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: 10 });+ expect(census).toMatchObject({ complete: true, pages: 3, states: { equal: 1, undeclared_database_only: 2 } });+ expect(census.sample.find(item => item.slug === 'link/beyond')).toMatchObject({ path: 'link/beyond.md', state: 'undeclared_database_only' });+ });+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');