Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

lint: missing-created accepts any temporal key and --fix no longer writes ingest time into created (#5433)

garrytan10cd81ab9e04
diff --git a/docs/architecture/key-files/commands-4.md b/docs/architecture/key-files/commands-4.md
index 0573208a6d..54c9da6ad0 100644
--- a/docs/architecture/key-files/commands-4.md
+++ b/docs/architecture/key-files/commands-4.md
@@ -20,7 +20,7 @@ Current behavior and load-bearing invariants; history belongs in Git and CHANGEL
- `src/commands/jobs.ts:refreshGatewayForJob` + `src/core/ai/gateway.ts:refreshGatewayEnvFromFilePlane` — long-lived-worker staleness boundary, three tiers: (1) DB-plane model config re-resolves per gateway-refresh job (`reconfigureGatewayWithEngine`); (2) FILE-plane config (`~/.gbrain/config.json`, incl. provider API keys) re-folds per job via the env-ONLY `refreshGatewayEnvFromFilePlane` — never a full `configureGateway(buildGatewayConfig(loadConfig()))`, which would clobber DB-plane-merged fields (base_urls, chat options) with file-plane-only values; (3) true process env vars are fixed at worker start and need a restart. `gbrain config set *_api_key` writes the DB plane, which `loadConfigWithEngine()` deliberately never merges for key fields — those writes do NOT reach workers (TODO filed to reroute them to the file plane). `facts-absorb` sits in `GATEWAY_REFRESH_JOB_NAMES`; its handler converts execution-time `chat_unavailable` in a KEYED worker into a typed retryable failure (`factsAbsorbShouldRetry`) while a keyless worker defers it (`JobDeferredError`, 30 min, no attempt counted) so the backlog runs once a key exists. Pinned by `test/jobs-gateway-refresh.serial.test.ts`.
-- `src/commands/lint.ts` — Page quality linter (catches LLM artifacts, placeholder dates). `runLintCore(opts)` walks the tree ONCE; `--fix` applies fixes during that same scan and reports per-page results through the `onPageIssues(relPath, issues, fixedCount)` callback (issues = what remains after this run's fix attempt for the page; `fixedCount` = fixes actually applied), so the summary's auto-fixed count is the true count — a second scan run after fixing would see already-fixed files and report zero. `onScanStart` fires once with the collected page count for progress wiring. Pinned by `test/lint-fix-single-pass.test.ts`. On a durability-hardened brain (`isDurabilityHardened` on the target dir, or the page's directory for a single-file target) every non-dry-run `--fix` repair is committed path-limited via `commitWriteThroughFile` right after the `writeFileSync` — the same contract as put_page write-through, so the cycle, the `lint`/`lint-fix` minion handlers and the CLI never leave hardened repairs as uncommitted drift for the sync phase to flag (pinned by `test/cycle-lint-durability.test.ts`). Lint rules `huge-page` (flags pages exceeding `content_sanity.bytes_warn`) and `scraper-junk` (flags pages matching any junk pattern). Both reuse `assessContent()` from `src/core/content-sanity.ts` so lint, doctor, and ingest share one assessor. `lint.ts` lifts DB config when `~/.gbrain/` is reachable; falls back to file/env on CI. Pinned by `test/lint-content-sanity.test.ts`. Rule `type-undeclared` flags an explicit frontmatter `type` the active schema pack neither declares nor aliases (resolved once per run from the shared/probed engine's DB-plane `schema_pack`, else file/env config; no resolvable pack skips it; `LintOpts.typePack` injects it), pinned by `test/lint-page-type-vocabulary.test.ts`. with `src/commands/sources.ts`: `gbrain lint` has a `markup-heavy` rule (flags pages whose prose-vs-markup ratio exceeds `content_sanity.max_markup_ratio`, reusing `assessContentSanity` so lint/gate/scan share one assessor); pinned by `test/lint-content-sanity.test.ts`. `gbrain sources audit <id>` is disposition-aware: its dry-run disk scan reports would-quarantine / would-reject / would-flag counts driven by the effective `content_sanity.junk_disposition` + markup config, so an operator previews the gate's verdict before sync. The `content-sanity-audit` JSONL (`src/core/audit/content-sanity-audit.ts`) records the quarantine/flag dispositions. On a managed brain (persistence enabled) `runLintCore` skips the legacy filesystem lock and publishes each repair through the persistence coordinator (`maintenancePreflight` + `publishMaintenancePage`: DB row and worktree file in one guarded write) instead of writing the file. It reads the page revision before the bytes it repairs, checks them with the coordinator's canonical predicate (`fileMatchesSnapshot`, so formatting differences are not divergence) and submits against that revision. A repair that must wait (no indexed page, a file that diverged from the database, a held or removed file, a publication mid-scan) is a non-fixable `managed-write-pending` issue with `code: 'managed_write_pending'`, a `reason` (the coordinator refusal's detail, `held_file`, `canonical_file_missing`, `revision_changed`, `not_indexed`), the refusal's own rendered `fix` (never a sync) and the guide link; the run continues (`LintResult.write_path` / `fix_pending` / `pending_issues`, first 50; #5180, `test/managed-lint.test.ts` on both engines). A file the scan listed that is gone by its scan read (ENOENT only; other read errors still fail the run) is reported instead of aborting: a managed `--fix` run asks the coordinator (pending `canonical_file_missing`), otherwise a non-fixable `file-removed-during-scan` issue with code `file_removed_during_scan` and a `gbrain lint <target>` fix; the CLI prints each issue's `Fix:` command and `Docs:` link (`test/lint-file-removed-during-scan.test.ts`). `llm-preamble` matches only a leading run at a body start (file top, after leading frontmatter, or after a whole-page ```markdown wrapper), and repair removes only that run, so a later line that begins like a preamble is never flagged or deleted. A filesystem fix write refused with EACCES/EPERM/EROFS leaves the file unchanged and becomes a non-fixable `fix-not-writable` issue (`code: 'fix_not_writable'`, the errno as `reason`, a user `fix` naming the permission change or `--exclude`) counted in `fix_pending`; the run continues (`test/lint-preamble-anchor.test.ts`). `placeholder-date` and `empty-section` read code-masked text (`stripCodeBlocks`, offset-preserving): a placeholder or a `## ` line inside a fence or inline code is code, an unclosed fence masks to the end of the file, and `empty-section` reads each section's body from the original text, so a section holding only a code block is not empty (`test/lint-3958.test.ts`).
+- `src/commands/lint.ts` — Page quality linter (catches LLM artifacts, placeholder dates). `runLintCore(opts)` walks the tree ONCE; `--fix` applies fixes during that same scan and reports per-page results through the `onPageIssues(relPath, issues, fixedCount)` callback (issues = what remains after this run's fix attempt for the page; `fixedCount` = fixes actually applied), so the summary's auto-fixed count is the true count — a second scan run after fixing would see already-fixed files and report zero. `onScanStart` fires once with the collected page count for progress wiring. Pinned by `test/lint-fix-single-pass.test.ts`. On a durability-hardened brain (`isDurabilityHardened` on the target dir, or the page's directory for a single-file target) every non-dry-run `--fix` repair is committed path-limited via `commitWriteThroughFile` right after the `writeFileSync` — the same contract as put_page write-through, so the cycle, the `lint`/`lint-fix` minion handlers and the CLI never leave hardened repairs as uncommitted drift for the sync phase to flag (pinned by `test/cycle-lint-durability.test.ts`). Lint rules `huge-page` (flags pages exceeding `content_sanity.bytes_warn`) and `scraper-junk` (flags pages matching any junk pattern). Both reuse `assessContent()` from `src/core/content-sanity.ts` so lint, doctor, and ingest share one assessor. `lint.ts` lifts DB config when `~/.gbrain/` is reachable; falls back to file/env on CI. Pinned by `test/lint-content-sanity.test.ts`. Rule `type-undeclared` flags an explicit frontmatter `type` the active schema pack neither declares nor aliases (resolved once per run from the shared/probed engine's DB-plane `schema_pack`, else file/env config; no resolvable pack skips it; `LintOpts.typePack` injects it), pinned by `test/lint-page-type-vocabulary.test.ts`. with `src/commands/sources.ts`: `gbrain lint` has a `markup-heavy` rule (flags pages whose prose-vs-markup ratio exceeds `content_sanity.max_markup_ratio`, reusing `assessContentSanity` so lint/gate/scan share one assessor); pinned by `test/lint-content-sanity.test.ts`. `gbrain sources audit <id>` is disposition-aware: its dry-run disk scan reports would-quarantine / would-reject / would-flag counts driven by the effective `content_sanity.junk_disposition` + markup config, so an operator previews the gate's verdict before sync. The `content-sanity-audit` JSONL (`src/core/audit/content-sanity-audit.ts`) records the quarantine/flag dispositions. On a managed brain (persistence enabled) `runLintCore` skips the legacy filesystem lock and publishes each repair through the persistence coordinator (`maintenancePreflight` + `publishMaintenancePage`: DB row and worktree file in one guarded write) instead of writing the file. It reads the page revision before the bytes it repairs, checks them with the coordinator's canonical predicate (`fileMatchesSnapshot`, so formatting differences are not divergence) and submits against that revision. A repair that must wait (no indexed page, a file that diverged from the database, a held or removed file, a publication mid-scan) is a non-fixable `managed-write-pending` issue with `code: 'managed_write_pending'`, a `reason` (the coordinator refusal's detail, `held_file`, `canonical_file_missing`, `revision_changed`, `not_indexed`), the refusal's own rendered `fix` (never a sync) and the guide link; the run continues (`LintResult.write_path` / `fix_pending` / `pending_issues`, first 50; #5180, `test/managed-lint.test.ts` on both engines). A file the scan listed that is gone by its scan read (ENOENT only; other read errors still fail the run) is reported instead of aborting: a managed `--fix` run asks the coordinator (pending `canonical_file_missing`), otherwise a non-fixable `file-removed-during-scan` issue with code `file_removed_during_scan` and a `gbrain lint <target>` fix; the CLI prints each issue's `Fix:` command and `Docs:` link (`test/lint-file-removed-during-scan.test.ts`). `llm-preamble` matches only a leading run at a body start (file top, after leading frontmatter, or after a whole-page ```markdown wrapper), and repair removes only that run, so a later line that begins like a preamble is never flagged or deleted. A filesystem fix write refused with EACCES/EPERM/EROFS leaves the file unchanged and becomes a non-fixable `fix-not-writable` issue (`code: 'fix_not_writable'`, the errno as `reason`, a user `fix` naming the permission change or `--exclude`) counted in `fix_pending`; the run continues (`test/lint-preamble-anchor.test.ts`). `placeholder-date` and `empty-section` read code-masked text (`stripCodeBlocks`, offset-preserving): a placeholder or a `## ` line inside a fence or inline code is code, an unclosed fence masks to the end of the file, and `empty-section` reads each section's body from the original text, so a section holding only a code block is not empty (`test/lint-3958.test.ts`). #5433: `missing-created` fires only when none of `created`, `event_date`, `date`, `published`, `captured_at`, `ingested_at` parses (`parseDateLoose` on the parsed frontmatter, never a regex; a block YAML could not read is already `frontmatter-yaml-parse`) and is never fixable: `fixContent` no longer promotes a capture timestamp into `created` (ingest time is not creation time, and the cycle's `fix: true` lint phase rewrote every native page), so a page `serializePageToMarkdown` emits stays byte-identical across repeated `--fix` runs; `promoteCreatedFromCapture` stays exported, deprecated, for explicit callers.
- `src/commands/migrate-embeddings.ts` — `gbrain migrate embeddings --to <provider:model> [--dim N] [--dry-run] [--yes] [--json] [--no-embed] [--status] [--reranker auto|off|keep|<model>] [--retarget] [--batch-size N] [--pace[=mode]] [--ignore-env-override]` (alias: `gbrain retrieval-upgrade`). ONE shared orchestrator for CLI and the `migrate_embeddings` op: `planMigrationFlow` (plan + `verifyMigrationComplete` + env presence + un-merged file plane + brain/DB identity via `redactPgUrl` + concurrent-writer census + reranker plan + in-flight-other marker) and `executeMigrationFlow` (global `gbrain-embedding-migration` DbLock → retarget gate under it → all-source embed locks sorted with `includeArchived` → worst-case authorization under the locks (a cap below it returns `refused_budget` / op `refused` with `embedding_budget_below_worst_case` before any provider call or invalidation) → live embed probe → apply → reranker probe + switch → drain via `runEmbedCore({heldLocks, …})` so the migration never lock_skips itself, with a 5-min heartbeat whose refresh-false/3-errors ABORTS as `lock_lost` → reconcile → completion smoke check stamped into the marker → transactional complete; locks released in finally). The skip path exits 0 ONLY on `verify.complete` with no pending retarget decision and no pending reranker action (a resolved switch/disable runs as a config-only completion). `--status` is read-only/spend-free and never refuses on env (it REPORTS planes, key PRESENCE booleans only, censuses, markers verbatim incl. corrupt, the exact resume command, and the last completion + smoke-check outcome). `persistEmbeddingFileConfig` writes through `loadConfigFileOnly` (never persists env-sourced keys) and supports env-canonical no-file deployments (env pins target ⇒ proceed with notice). Exit codes: 0 completed/verified-no-work, 1 locked/refused/failed/incomplete (message names which; lock_skipped and lock_lost get their own copy), 3 consent required (agent operator wave C2: `requireConsent` with effects `paid` + `destructive`; `spend.posture=tokenmax` covers only the paid part, `--json` never implies consent, the payload's fix repeats the caller's argv plus `--yes`; the TTY prompt is interaction.readLine, and the `confirm`/`isTTY` test seams map onto ConsentEnv). Spend stays bounded by the durable `--max-cost-usd` authorization, not the consent cap. Pinned by `test/migrate-embeddings-flow.serial.test.ts`, `test/migrate-embeddings-boundary.serial.test.ts`, `test/migrate-embeddings-hardening.serial.test.ts`. Migration guidance uses `renderCanonicalMigrationCommands` (`src/core/ai/defaults.ts`) to keep supported targets and dimensions consistent.
diff --git a/src/commands/lint.ts b/src/commands/lint.ts
index 081a63436f..90d28fe9f4 100644
--- a/src/commands/lint.ts
+++ b/src/commands/lint.ts
@@ -22,6 +22,7 @@ import { readdirSync, statSync, lstatSync, existsSync } from 'fs';
import { join, relative, dirname } from 'path';
import { isAborted } from '../core/abort-check.ts';
import { parseMarkdown, type ParseValidationCode } from '../core/markdown.ts';
+import { parseDateLoose } from '../core/effective-date.ts';
import {
assessContentSanity,
type OperatorLiteral,
@@ -124,6 +125,13 @@ function findLeadingPreamble(content: string): { start: number; end: number } |
// ── Rules ──────────────────────────────────────────────────────────
+/**
+ * #5433: frontmatter keys that count as temporal provenance for the
+ * `missing-created` rule. `created` first for the legacy name; the rest are
+ * what effective-date resolution and the native serializer actually write.
+ */
+const TEMPORAL_KEYS = ['created', 'event_date', 'date', 'published', 'captured_at', 'ingested_at'] as const;
+
/**
* Per-call options for `lintContent`. Tests pass content-sanity opts
* directly so the linter can be exercised without an engine.
@@ -254,17 +262,17 @@ export function lintContent(content: string, filePath: string, opts: LintContent
fixable: false,
});
}
- if (!fm.match(/^created:/m)) {
- // #3958: when the page's own frontmatter carries a capture timestamp
- // (captured_at / ingested_at), `--fix` can promote it to `created` —
- // mark the finding fixable so the operator knows --fix will heal it.
- const promotable = /^(?:captured_at|ingested_at):/m.test(fm);
+ // #5433: the native serializer never writes `created` and effective-date
+ // resolution reads event_date / date / published, so any parseable
+ // temporal key is provenance enough. The rule name stays for consumers;
+ // it is never fixable (ingest time is not creation time, see #3958).
+ // A block YAML could not read is already a frontmatter-yaml-parse finding.
+ const yamlUnreadable = parsed.errors?.some(e => e.code === 'YAML_PARSE') ?? false;
+ if (!yamlUnreadable && !TEMPORAL_KEYS.some(key => parseDateLoose(parsed.frontmatter[key]) !== null)) {
issues.push({
file: filePath, line: 1, rule: 'missing-created',
- message: promotable
- ? 'Frontmatter missing required field: created (promotable from captured_at/ingested_at)'
- : 'Frontmatter missing required field: created',
- fixable: promotable,
+ message: `Frontmatter has no parseable date under any of: ${TEMPORAL_KEYS.join(', ')}`,
+ fixable: false,
});
}
}
@@ -388,11 +396,16 @@ export function lintContent(content: string, filePath: string, opts: LintContent
}
/**
- * #3958: promote `captured_at:` (preferred) or `ingested_at:` to `created:`
- * when the frontmatter has no `created:` of its own. The value is copied
- * verbatim (quoting preserved) and inserted directly below the source line.
- * No-op when there is no frontmatter, `created:` already exists, or neither
- * capture field is present. Pure + exported for tests.
+ * @deprecated #5433: no longer part of `fixContent`. Ingest time is when a
+ * file entered the brain, not when its content was created, and the cycle's
+ * lint phase ran this on every native page, diverging the file from the DB
+ * row that serialized it. Kept for callers who promote explicitly.
+ *
+ * Promotes `captured_at:` (preferred) or `ingested_at:` to `created:` when
+ * the frontmatter has no `created:` of its own. The value is copied verbatim
+ * (quoting preserved) and inserted directly below the source line. No-op
+ * when there is no frontmatter, `created:` already exists, or neither
+ * capture field is present.
*/
export function promoteCreatedFromCapture(content: string): string {
if (!content.startsWith('---')) return content;
@@ -418,11 +431,6 @@ export function fixContent(content: string): string {
fixed = fixed.replace(/^```(?:markdown|md)\s*\n/, '');
fixed = fixed.replace(/\n```\s*$/, '');
- // #3958: missing-created is fixable when the page's own frontmatter
- // carries a capture timestamp. Runs after the fence unwrap so a wrapped
- // page's frontmatter is visible to the promotion.
- fixed = promoteCreatedFromCapture(fixed);
-
// Clean up excessive blank lines left by fixes
fixed = fixed.replace(/\n{3,}/g, '\n\n');
diff --git a/test/cycle-lint-durability.test.ts b/test/cycle-lint-durability.test.ts
index 834d7086e2..ec2af51509 100644
--- a/test/cycle-lint-durability.test.ts
+++ b/test/cycle-lint-durability.test.ts
@@ -14,7 +14,8 @@ afterEach(() => {
/**
* A committed git repo carrying the gbrain durability post-commit hook and
- * one page whose only lint issue is fixable (ingested_at without created).
+ * one page whose only lint issue is fixable (a leading LLM preamble; #5433
+ * made `ingested_at` count as temporal provenance, so it is not a finding).
*/
function hardenedRepoWithNote(opts: { hook?: boolean } = {}): { root: string; page: string } {
const root = mkdtempSync(join(tmpdir(), 'gbrain-cycle-lint-durability-'));
@@ -22,7 +23,7 @@ function hardenedRepoWithNote(opts: { hook?: boolean } = {}): { root: string; pa
const page = join(root, 'note.md');
writeFileSync(
page,
- `---\ntype: note\ntitle: Durable\nstatus: active\ningested_at: '2026-08-30T12:00:00Z'\n---\n\nBody.\n`,
+ `---\ntype: note\ntitle: Durable\nstatus: active\ningested_at: '2026-08-30T12:00:00Z'\n---\n\nOf course. Here is the page.\n\nBody.\n`,
);
execFileSync('git', ['init', '-q'], { cwd: root });
execFileSync('git', ['config', 'user.name', 'Test'], { cwd: root });
diff --git a/test/lint-3958.test.ts b/test/lint-3958.test.ts
index d96dbfb031..fd58691f98 100644
--- a/test/lint-3958.test.ts
+++ b/test/lint-3958.test.ts
@@ -4,9 +4,10 @@
* 1. The "Run with --fix" hint only prints when at least one finding is
* actually fixable (LintResult.total_fixable), so an all-unfixable report
* can't send the operator on a no-op --fix run.
- * 2. missing-created is FIXABLE when the page's own frontmatter carries a
- * capture timestamp (captured_at / ingested_at) — fixContent promotes it
- * to created.
+ * 2. (superseded by #5433) missing-created used to be FIXABLE when the
+ * page's own frontmatter carried a capture timestamp. Ingest time is not
+ * creation time, so the promotion is out of fixContent; the rule now
+ * accepts any parseable temporal key and is never fixable.
* 3. placeholder-date skips lines inside fenced code blocks: a page
* DOCUMENTING date formats (```\ncreated: YYYY-MM-DD\n```) is not a page
* with an unfilled placeholder.
@@ -23,6 +24,8 @@ import {
runLintCore,
runLint,
} from '../src/commands/lint.ts';
+import { serializePageToMarkdown } from '../src/core/markdown.ts';
+import type { Page } from '../src/core/types.ts';
const SANITY_OFF = { disabled: true } as const;
@@ -119,62 +122,65 @@ describe('#6257 empty-section ignores headings inside code fences', () => {
});
});
-describe('#3958 missing-created is fixable via capture-timestamp promotion', () => {
- test('captured_at present -> missing-created is fixable', () => {
- const content = '---\ntitle: T\ntype: note\ncaptured_at: 2026-01-05T10:00:00Z\n---\n\n# T\n\nBody.\n';
- const issues = lintContent(content, 'test.md', { contentSanity: SANITY_OFF });
- const mc = issues.find(i => i.rule === 'missing-created');
- expect(mc).toBeDefined();
- expect(mc!.fixable).toBe(true);
- });
+describe('#5433 missing-created accepts any temporal key and is never fixable', () => {
+ const rule = (content: string) =>
+ lintContent(content, 'test.md', { contentSanity: SANITY_OFF }).filter(i => i.rule === 'missing-created');
- test('no capture field -> missing-created stays unfixable', () => {
- const content = '---\ntitle: T\ntype: note\n---\n\n# T\n\nBody.\n';
- const issues = lintContent(content, 'test.md', { contentSanity: SANITY_OFF });
- const mc = issues.find(i => i.rule === 'missing-created');
- expect(mc).toBeDefined();
- expect(mc!.fixable).toBe(false);
+ test.each([
+ ['created', 'created: 2026-01-05'],
+ ['event_date', 'event_date: 2026-01-05'],
+ ['date', 'date: 2026-01-05'],
+ ['published', 'published: "2026-01-05"'],
+ ['captured_at', 'captured_at: 2026-01-05T10:00:00Z'],
+ ['ingested_at', "ingested_at: '2026-01-05T10:00:00.000Z'"],
+ ])('%s alone satisfies the rule', (_key, line) => {
+ expect(rule(`---\ntitle: T\ntype: note\n${line}\n---\n\n# T\n\nBody.\n`)).toEqual([]);
});
- test('promoteCreatedFromCapture copies captured_at verbatim', () => {
- const content = '---\ntitle: T\ncaptured_at: 2026-01-05T10:00:00Z\n---\n\nBody.\n';
- const out = promoteCreatedFromCapture(content);
- expect(out).toContain('created: 2026-01-05T10:00:00Z');
- // Inserted inside the frontmatter block, directly after captured_at.
- expect(out.indexOf('created:')).toBeGreaterThan(out.indexOf('captured_at:'));
- expect(out.indexOf('created:')).toBeLessThan(out.indexOf('---', 3) + 4);
+ test('no temporal key -> missing-created, unfixable', () => {
+ const hits = rule('---\ntitle: T\ntype: note\n---\n\n# T\n\nBody.\n');
+ expect(hits).toHaveLength(1);
+ expect(hits[0].fixable).toBe(false);
+ expect(hits[0].message).toContain('event_date');
});
- test('promoteCreatedFromCapture falls back to ingested_at', () => {
- const content = '---\ntitle: T\ningested_at: "2026-02-01"\n---\n\nBody.\n';
- const out = promoteCreatedFromCapture(content);
- expect(out).toContain('created: "2026-02-01"');
+ test('an unparseable value does not count (placeholder, garbage)', () => {
+ expect(rule('---\ntitle: T\ntype: note\ncreated: YYYY-MM-DD\n---\n\n# T\n')).toHaveLength(1);
+ expect(rule('---\ntitle: T\ntype: note\ncreated: soonish\ncaptured_at: 2026-02-30\n---\n\n# T\n')).toHaveLength(1);
});
- test('promoteCreatedFromCapture prefers captured_at over ingested_at', () => {
- const content = '---\ntitle: T\ningested_at: 2026-02-01\ncaptured_at: 2026-01-05\n---\n\nBody.\n';
- const out = promoteCreatedFromCapture(content);
- expect(out).toContain('created: 2026-01-05');
- expect(out).not.toContain('created: 2026-02-01');
+ test('a page the native serializer emits (ingested_at only) is clean and fixContent leaves it byte-identical', () => {
+ const page = {
+ slug: 'notes/example', title: 'Example', type: 'note', compiled_truth: '# Example\n\nBody.', timeline: '',
+ frontmatter: { ingested_at: '2026-01-05T10:00:00.000Z' },
+ } as unknown as Page;
+ const content = serializePageToMarkdown(page, []);
+ expect(content).not.toContain('created:');
+ const issues = lintContent(content, 'notes/example.md', { contentSanity: SANITY_OFF });
+ expect(issues.filter(i => i.rule === 'missing-created')).toEqual([]);
+ expect(issues.some(i => i.fixable)).toBe(false);
+ expect(fixContent(content)).toBe(content);
+ expect(fixContent(fixContent(content))).toBe(content);
});
- test('promoteCreatedFromCapture is a no-op when created exists / no frontmatter', () => {
- const withCreated = '---\ntitle: T\ncreated: 2025-12-31\ncaptured_at: 2026-01-05\n---\n\nBody.\n';
- expect(promoteCreatedFromCapture(withCreated)).toBe(withCreated);
- const noFm = '# Just a heading\n\ncaptured_at: 2026-01-05\n';
- expect(promoteCreatedFromCapture(noFm)).toBe(noFm);
- });
-
- test('fixContent heals missing-created end-to-end (incl. fence-wrapped pages)', () => {
- const wrapped =
- '```markdown\n---\ntitle: T\ntype: note\ncaptured_at: 2026-01-05\n---\n\n# T\n\nBody.\n```';
+ test('fixContent no longer promotes a capture timestamp (fence unwrap still works)', () => {
+ const wrapped = '```markdown\n---\ntitle: T\ntype: note\ncaptured_at: 2026-01-05\n---\n\n# T\n\nBody.\n```';
const fixed = fixContent(wrapped);
expect(fixed.startsWith('---')).toBe(true);
- expect(fixed).toContain('created: 2026-01-05');
+ expect(fixed).not.toContain('created:');
const after = lintContent(fixed, 'test.md', { contentSanity: SANITY_OFF });
expect(after.filter(i => i.rule === 'missing-created')).toHaveLength(0);
expect(after.filter(i => i.rule === 'code-fence-wrap')).toHaveLength(0);
});
+
+ test('promoteCreatedFromCapture is still exported for explicit callers (deprecated)', () => {
+ const content = '---\ntitle: T\ningested_at: 2026-02-01\ncaptured_at: 2026-01-05\n---\n\nBody.\n';
+ const out = promoteCreatedFromCapture(content);
+ expect(out).toContain('created: 2026-01-05');
+ expect(out).not.toContain('created: 2026-02-01');
+ const withCreated = '---\ntitle: T\ncreated: 2025-12-31\ncaptured_at: 2026-01-05\n---\n\nBody.\n';
+ expect(promoteCreatedFromCapture(withCreated)).toBe(withCreated);
+ });
});
describe('#3958 total_fixable + the --fix hint gate', () => {
@@ -188,26 +194,43 @@ describe('#3958 total_fixable + the --fix hint gate', () => {
test('runLintCore reports total_fixable separately from total_issues', async () => {
// One unfixable issue (placeholder-date in the body) + one fixable page
- // (missing-created promotable from captured_at).
+ // (an LLM preamble; #5433 took missing-created out of the fixable set).
writeFileSync(
join(dir, 'unfixable.md'),
'---\ntitle: A\ntype: note\ncreated: 2026-01-05\n---\n\n- 2026-XX-XX | pending\n',
);
writeFileSync(
join(dir, 'fixable.md'),
- '---\ntitle: B\ntype: note\ncaptured_at: 2026-01-05\n---\n\n# B\n\nBody.\n',
+ '---\ntitle: B\ntype: note\ncaptured_at: 2026-01-05\n---\n\nOf course. Here is the page.\n\n# B\n\nBody.\n',
);
const result = await runLintCore({ target: dir, contentSanity: SANITY_OFF as never });
expect(result.total_issues).toBe(2);
expect(result.total_fixable).toBe(1);
});
- test('runLintCore --fix writes the promoted created field', async () => {
+ test('runLintCore --fix strips the preamble and never writes created', async () => {
const page = join(dir, 'fixable.md');
- writeFileSync(page, '---\ntitle: B\ntype: note\ncaptured_at: 2026-01-05\n---\n\n# B\n\nBody.\n');
+ writeFileSync(page, '---\ntitle: B\ntype: note\ncaptured_at: 2026-01-05\n---\n\nOf course. Here is the page.\n\n# B\n\nBody.\n');
const result = await runLintCore({ target: dir, fix: true, contentSanity: SANITY_OFF as never });
expect(result.total_fixed).toBe(1);
- expect(readFileSync(page, 'utf-8')).toContain('created: 2026-01-05');
+ const after = readFileSync(page, 'utf-8');
+ expect(after).not.toContain('Of course');
+ expect(after).not.toContain('created:');
+ });
+
+ test('#5433 repeated --fix runs leave a native (ingested_at-only) page byte-identical', async () => {
+ const page = join(dir, 'native.md');
+ const content = serializePageToMarkdown({
+ slug: 'native', title: 'Native', type: 'note', compiled_truth: '# Native\n\nBody.', timeline: '',
+ frontmatter: { ingested_at: '2026-01-05T10:00:00.000Z' },
+ } as unknown as Page, ['alpha']);
+ writeFileSync(page, content);
+ for (let i = 0; i < 3; i++) {
+ const result = await runLintCore({ target: dir, fix: true, contentSanity: SANITY_OFF as never });
+ expect(result.total_fixed).toBe(0);
+ expect(result.total_fixable).toBe(0);
+ expect(readFileSync(page, 'utf-8')).toBe(content);
+ }
});
test('hint prints only when something is fixable', async () => {
@@ -228,7 +251,7 @@ describe('#3958 total_fixable + the --fix hint gate', () => {
// Add a fixable page: the hint appears.
writeFileSync(
join(dir, 'fixable.md'),
- '---\ntitle: B\ntype: note\ncaptured_at: 2026-01-05\n---\n\n# B\n\nBody.\n',
+ '---\ntitle: B\ntype: note\ncaptured_at: 2026-01-05\n---\n\nOf course. Here is the page.\n\n# B\n\nBody.\n',
);
const logged2: string[] = [];
console.log = (...a: unknown[]) => { logged2.push(a.join(' ')); };
diff --git a/test/managed-lint.test.ts b/test/managed-lint.test.ts
index b8f85ff369..ee0ca283d8 100644
--- a/test/managed-lint.test.ts
+++ b/test/managed-lint.test.ts
@@ -26,10 +26,10 @@ import { waitFor } from './helpers/wait-for.ts';
const PREAMBLE = 'Of course. Here is a detailed brain page for Jane Doe.\n\n';
const BODY = '# Jane Doe\n\nContent that stays.\n';
const PAGE = `---\ntitle: Jane Doe\ntype: person\n---\n${PREAMBLE}${BODY}`;
-// A page the coordinator wrote carries `ingested_at`, so lint sees TWO fixable
-// issues on it: the LLM preamble and `missing-created` (promotable from
-// `ingested_at`, #3958). A hand-written file has only the preamble to fix.
-const FIXABLE_ON_INDEXED_PAGE = 2;
+// A page the coordinator wrote carries `ingested_at`; since #5433 that counts
+// as temporal provenance (no `missing-created`, nothing to promote), so lint
+// sees ONE fixable issue on it: the LLM preamble. Same as a hand-written file.
+const FIXABLE_ON_INDEXED_PAGE = 1;
const engines: BrainEngine[] = [];
const dataDir = mkdtempSync(join(tmpdir(), 'gbrain-managed-lint-db-'));
@@ -133,7 +133,7 @@ test('managed lint leaves a file with no indexed page pending instead of writing
const seen: Array<{ rel: string; rules: string[] }> = [];
const result = await runLintCore({ target: root, fix: true, engine, sourceId,
onPageIssues: (rel, issues) => seen.push({ rel, rules: issues.map(i => i.rule) }) });
- // jane-doe: 2 fixable, fixed. stray: preamble fixable but unpublishable (+1 pending issue), missing-created not promotable.
+ // jane-doe: 1 fixable, fixed. stray: preamble fixable but unpublishable (+1 pending issue).
expect(result).toMatchObject({ pages_scanned: 2, total_fixable: FIXABLE_ON_INDEXED_PAGE + 1, total_fixed: FIXABLE_ON_INDEXED_PAGE, fix_pending: 1, write_path: 'coordinator' });
expect(readFileSync(stray, 'utf8')).toBe(PAGE);
expect(seen.find(s => s.rel === 'notes/stray.md')?.rules).toContain('managed-write-pending');
diff --git a/test/managed-phase-matrix.test.ts b/test/managed-phase-matrix.test.ts
index fdf002ff9d..b575188dc3 100644
--- a/test/managed-phase-matrix.test.ts
+++ b/test/managed-phase-matrix.test.ts
@@ -109,8 +109,8 @@ async function seedFacts(engine: BrainEngine, sourceId: string, slug: string) {
const MATRIX: Record<CyclePhase, Entry> = {
lint: {
- seed: async ({ engine, sourceId }) => put(engine, sourceId, 'notes/lint-example', page('note', 'Lint example', 'Body with a trailing space. \n\n\n\nToo many blank lines.')),
- // #5180: the seeded page has a fixable issue (missing-created, promotable from its capture timestamp);
+ seed: async ({ engine, sourceId }) => put(engine, sourceId, 'notes/lint-example', page('note', 'Lint example', 'Of course. Here is a detailed brain page.\n\n# Lint example\n\nBody.')),
+ // #5180: the seeded page has a fixable issue (an LLM preamble; #5433 took the capture-timestamp promotion out);
// the repair is admitted and committed by the coordinator, never written to the worktree by lint itself.
assert: async ({ engine, sourceId, result }) => {
expect(await committed(engine, sourceId, 'notes/lint-example')).not.toHaveLength(0);