fix(ms-ai-architect): RX-OPS2 skrive-sikkerhet i driverne — scoped restore + atomiske skriv [skip-docs]
- backup.mjs restore(relPaths): SCOPED per-fil-rollback erstatter hel-tre rmSync(srcDir)+cpSync. Ruller kun tilbake kjøringens egne skriv; parallelle økters skriv til søsken-filer overlever; intet destruktivt rm→cp-vindu. Nyskapte filer slettes; prior bytes gjenopprettes atomisk. - migrate-corpus.mjs: returnert restore() er nå en null-arg closure bundet til kjøringens skrive- liste (public API uendret) → scoped. detectStaleRollback aborterer ved forrige krasj-sentinel; cleanupOldBackups pruner backups forbi retention etter vellykket batch. - 5 drivere (backfill-status/-category, dedup-plain-header, relabel-dato/-dialect): writeFileSync → atomicWriteSync (crash-safe tmp+rename) + recovery-kontrakt i header. - backfill-category.mjs: refaktorert importerbar (isMain-guard + run()/planCategoryBackfill/ categoryForFile/FOLDER_CATEGORY-eksporter, parameterisert root) → testbar uten scan-side-effekt. - Tester (+16): 6 scoped-restore (parallel-preservering, ny-fil-sletting, throws-guard) erstatter 2 hel-tre; test-backfill-category (frosset taxonomi + hermetisk plan); test-driver-atomic-writes (5 drivere); migrate stale-abort + cleanup-wiring. Suite 859→875 exit 0. validate-plugin 250/0.
This commit is contained in:
parent
b68514487c
commit
b3011da017
11 changed files with 406 additions and 100 deletions
|
|
@ -8,19 +8,26 @@
|
|||
// change by more than that single line, the run aborts and writes nothing. Idempotent:
|
||||
// files that already carry **Category:**/**Kategori:** are skipped, so a re-run is a no-op.
|
||||
//
|
||||
// The planning is factored into pure/importable pieces (categoryForFile + planCategoryBackfill)
|
||||
// behind an isMain guard, so the frozen taxonomy and the plan can be tested without executing
|
||||
// the corpus scan as an import side effect.
|
||||
//
|
||||
// Recovery contract: writes are crash-safe (atomicWriteSync tmp+rename — a reader sees the old
|
||||
// file or the new one, never a partial); an interrupted run is recovered by re-running (idempotent).
|
||||
//
|
||||
// Usage: node scripts/kb-update/backfill-category.mjs [--dry]
|
||||
import { readFileSync, writeFileSync } from 'node:fs';
|
||||
import { readFileSync, realpathSync } from 'node:fs';
|
||||
import { execSync } from 'node:child_process';
|
||||
import { join, dirname } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { insertMetaField } from './lib/transform.mjs';
|
||||
import { atomicWriteSync } from './lib/atomic-write.mjs';
|
||||
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||
const PLUGIN_ROOT = join(__dirname, '..', '..');
|
||||
const dry = process.argv.includes('--dry');
|
||||
|
||||
// Immediate-parent-directory basename → Category. Operator-approved 2026-07-06.
|
||||
const FOLDER_CATEGORY = {
|
||||
// Immediate-parent-directory basename → Category. Operator-approved 2026-07-06 (frozen).
|
||||
export const FOLDER_CATEGORY = {
|
||||
architecture: 'Solution Architecture & Advisory',
|
||||
platforms: 'Microsoft AI Platforms',
|
||||
development: 'Microsoft AI Platforms',
|
||||
|
|
@ -30,53 +37,88 @@ const FOLDER_CATEGORY = {
|
|||
|
||||
const RE_CAT = /^\s*\*\*(Category|Kategori):\*\*/im;
|
||||
|
||||
const files = execSync("find skills/*/references -name '*.md'", { cwd: PLUGIN_ROOT, encoding: 'utf8' })
|
||||
.trim()
|
||||
.split('\n');
|
||||
|
||||
const targets = files.filter((rel) => !RE_CAT.test(readFileSync(join(PLUGIN_ROOT, rel), 'utf8')));
|
||||
|
||||
const planned = [];
|
||||
const unmatched = [];
|
||||
for (const rel of targets) {
|
||||
const folder = rel.split('/').slice(-2, -1)[0];
|
||||
const cat = FOLDER_CATEGORY[folder];
|
||||
if (!cat) {
|
||||
unmatched.push(`${rel} (folder=${folder})`);
|
||||
continue;
|
||||
}
|
||||
const old = readFileSync(join(PLUGIN_ROOT, rel), 'utf8');
|
||||
const out = insertMetaField(old, 'Category', cat);
|
||||
// Hard invariant: exactly one line inserted (the Category line), body byte-identical.
|
||||
const o = old.split('\n');
|
||||
const n = out.split('\n');
|
||||
if (n.length !== o.length + 1) throw new Error(`ABORT ${rel}: not exactly one line inserted`);
|
||||
let d = 0;
|
||||
while (d < o.length && o[d] === n[d]) d++;
|
||||
if (n[d] !== `**Category:** ${cat}`) {
|
||||
throw new Error(`ABORT ${rel}: inserted line mismatch → ${JSON.stringify(n[d])}`);
|
||||
}
|
||||
if (o.slice(d).join('\n') !== n.slice(d + 1).join('\n')) {
|
||||
throw new Error(`ABORT ${rel}: body not byte-identical below the insertion`);
|
||||
}
|
||||
planned.push({ rel, cat, out });
|
||||
/**
|
||||
* The Category for a reference file, keyed on its immediate-parent folder. Pure.
|
||||
* @param {string} rel — plugin-relative path
|
||||
* @returns {string|null} the approved Category, or null when the folder is outside the rule
|
||||
*/
|
||||
export function categoryForFile(rel) {
|
||||
const folder = String(rel ?? '').split('/').slice(-2, -1)[0];
|
||||
return FOLDER_CATEGORY[folder] ?? null;
|
||||
}
|
||||
|
||||
if (unmatched.length) {
|
||||
console.error(`ABORT — ${unmatched.length} target(s) outside the approved folder rule:`);
|
||||
unmatched.forEach((u) => console.error(' ' + u));
|
||||
process.exit(1);
|
||||
/**
|
||||
* Plan the Category backfill under `root` (reads files; performs NO writes). Discovers every
|
||||
* reference file, keeps only those missing a Category, and for each in an approved folder builds
|
||||
* the insert-only mutation behind the one-line/byte-identical invariant. Files outside the
|
||||
* approved folder rule are collected as `unmatched` (never planned for a write).
|
||||
* @param {string} root — corpus root (contains skills/…)
|
||||
* @returns {{files: string[], targets: string[], planned: {rel:string,cat:string,out:string}[], unmatched: string[]}}
|
||||
*/
|
||||
export function planCategoryBackfill(root) {
|
||||
const files = execSync("find skills/*/references -name '*.md'", { cwd: root, encoding: 'utf8' })
|
||||
.trim()
|
||||
.split('\n')
|
||||
.filter(Boolean);
|
||||
|
||||
const targets = files.filter((rel) => !RE_CAT.test(readFileSync(join(root, rel), 'utf8')));
|
||||
|
||||
const planned = [];
|
||||
const unmatched = [];
|
||||
for (const rel of targets) {
|
||||
const cat = categoryForFile(rel);
|
||||
if (!cat) {
|
||||
const folder = String(rel).split('/').slice(-2, -1)[0];
|
||||
unmatched.push(`${rel} (folder=${folder})`);
|
||||
continue;
|
||||
}
|
||||
const old = readFileSync(join(root, rel), 'utf8');
|
||||
const out = insertMetaField(old, 'Category', cat);
|
||||
// Hard invariant: exactly one line inserted (the Category line), body byte-identical.
|
||||
const o = old.split('\n');
|
||||
const n = out.split('\n');
|
||||
if (n.length !== o.length + 1) throw new Error(`ABORT ${rel}: not exactly one line inserted`);
|
||||
let d = 0;
|
||||
while (d < o.length && o[d] === n[d]) d++;
|
||||
if (n[d] !== `**Category:** ${cat}`) {
|
||||
throw new Error(`ABORT ${rel}: inserted line mismatch → ${JSON.stringify(n[d])}`);
|
||||
}
|
||||
if (o.slice(d).join('\n') !== n.slice(d + 1).join('\n')) {
|
||||
throw new Error(`ABORT ${rel}: body not byte-identical below the insertion`);
|
||||
}
|
||||
planned.push({ rel, cat, out });
|
||||
}
|
||||
return { files, targets, planned, unmatched };
|
||||
}
|
||||
|
||||
const byCat = {};
|
||||
for (const p of planned) byCat[p.cat] = (byCat[p.cat] || 0) + 1;
|
||||
console.log(`Reference files: ${files.length} | without a category: ${targets.length} | planned: ${planned.length}`);
|
||||
console.log('By category:');
|
||||
for (const [c, n] of Object.entries(byCat).sort()) console.log(` ${n} ${c}`);
|
||||
function run({ root = PLUGIN_ROOT, dry }) {
|
||||
const { files, targets, planned, unmatched } = planCategoryBackfill(root);
|
||||
|
||||
if (dry) {
|
||||
console.log('\n(dry run — no writes)');
|
||||
process.exit(0);
|
||||
if (unmatched.length) {
|
||||
console.error(`ABORT — ${unmatched.length} target(s) outside the approved folder rule:`);
|
||||
unmatched.forEach((u) => console.error(' ' + u));
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const byCat = {};
|
||||
for (const p of planned) byCat[p.cat] = (byCat[p.cat] || 0) + 1;
|
||||
console.log(`Reference files: ${files.length} | without a category: ${targets.length} | planned: ${planned.length}`);
|
||||
console.log('By category:');
|
||||
for (const [c, n] of Object.entries(byCat).sort()) console.log(` ${n} ${c}`);
|
||||
|
||||
if (dry) {
|
||||
console.log('\n(dry run — no writes)');
|
||||
return;
|
||||
}
|
||||
for (const p of planned) atomicWriteSync(join(root, p.rel), p.out);
|
||||
console.log(`\nWrote ${planned.length} files.`);
|
||||
}
|
||||
for (const p of planned) writeFileSync(join(PLUGIN_ROOT, p.rel), p.out);
|
||||
console.log(`\nWrote ${planned.length} files.`);
|
||||
|
||||
const isMain = (() => {
|
||||
try {
|
||||
return realpathSync(process.argv[1]) === realpathSync(fileURLToPath(import.meta.url));
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
})();
|
||||
if (isMain) run({ dry: process.argv.includes('--dry') });
|
||||
|
|
|
|||
|
|
@ -22,11 +22,15 @@
|
|||
// **Status:** in its header window is skipped, so a re-run — including the 14 R21 files already
|
||||
// applied — is a no-op. Aborts and writes nothing on any drift or invariant breach.
|
||||
//
|
||||
// Recovery contract: writes are crash-safe (atomicWriteSync tmp+rename — a reader sees the old
|
||||
// file or the new one, never a partial); an interrupted run is recovered by re-running (idempotent).
|
||||
//
|
||||
// Usage: node scripts/kb-update/backfill-status.mjs [--dry]
|
||||
import { readFileSync, writeFileSync, existsSync, realpathSync } from 'node:fs';
|
||||
import { readFileSync, existsSync, realpathSync } from 'node:fs';
|
||||
import { join, dirname, basename } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { insertMetaField } from './lib/transform.mjs';
|
||||
import { atomicWriteSync } from './lib/atomic-write.mjs';
|
||||
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||
const PLUGIN_ROOT = join(__dirname, '..', '..');
|
||||
|
|
@ -143,7 +147,7 @@ function run({ dry }) {
|
|||
for (const p of planned) console.log(` + ${p.rel} → **Status:** ${p.status}`);
|
||||
return;
|
||||
}
|
||||
for (const p of planned) writeFileSync(join(PLUGIN_ROOT, p.rel), p.out);
|
||||
for (const p of planned) atomicWriteSync(join(PLUGIN_ROOT, p.rel), p.out);
|
||||
console.log(`\nWrote ${planned.length} files.`);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,11 +21,15 @@
|
|||
//
|
||||
// Closes the last 4 of the corpus's Missing-Status and all 4 Missing-English-Last-updated.
|
||||
//
|
||||
// Recovery contract: writes are crash-safe (atomicWriteSync tmp+rename — a reader sees the old
|
||||
// file or the new one, never a partial); an interrupted run is recovered by re-running (idempotent).
|
||||
//
|
||||
// Usage: node scripts/kb-update/dedup-plain-header.mjs [--dry]
|
||||
import { readFileSync, writeFileSync, existsSync, realpathSync } from 'node:fs';
|
||||
import { readFileSync, existsSync, realpathSync } from 'node:fs';
|
||||
import { join, dirname } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { boldifyPlainField, dropRedundantPlainField } from './lib/transform.mjs';
|
||||
import { atomicWriteSync } from './lib/atomic-write.mjs';
|
||||
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||
const PLUGIN_ROOT = join(__dirname, '..', '..');
|
||||
|
|
@ -125,7 +129,7 @@ function run({ dry }) {
|
|||
for (const p of planned) console.log(` ~ ${p.rel}`);
|
||||
return;
|
||||
}
|
||||
for (const p of planned) writeFileSync(join(PLUGIN_ROOT, p.rel), p.out);
|
||||
for (const p of planned) atomicWriteSync(join(PLUGIN_ROOT, p.rel), p.out);
|
||||
console.log(`\nWrote ${planned.length} files.`);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,12 @@
|
|||
// backup.mjs — Backup + sentinel-guarded rollback for skills/-tree.
|
||||
// backup.mjs — Backup + sentinel-guarded, SCOPED rollback for skills/-tree.
|
||||
// Zero dependencies. Uses fs.cpSync (recursive + preserveTimestamps) without
|
||||
// dereference (Node 22.17.x regression) and without filter (Windows symlink-
|
||||
// type bug). Rollback writes a .rollback-in-progress sentinel at backupRoot
|
||||
// BEFORE destructive operations and removes it on success — a crash mid-
|
||||
// restore leaves the sentinel behind so detectStaleRollback() can flag it.
|
||||
// type bug). restore(relPaths) rolls back ONLY the relative paths the calling
|
||||
// run wrote — never the whole tree — so a parallel session's writes to sibling
|
||||
// files survive and there is no destructive rm→cp window. It writes a
|
||||
// .rollback-in-progress sentinel at backupRoot BEFORE the first per-file restore
|
||||
// and removes it on success — a crash mid-restore leaves the sentinel behind so
|
||||
// detectStaleRollback() can flag it.
|
||||
|
||||
import {
|
||||
cpSync,
|
||||
|
|
@ -15,8 +18,8 @@ import {
|
|||
unlinkSync,
|
||||
mkdirSync,
|
||||
} from 'node:fs';
|
||||
import { join, basename } from 'node:path';
|
||||
import { atomicWriteJson } from './atomic-write.mjs';
|
||||
import { join, basename, dirname } from 'node:path';
|
||||
import { atomicWriteJson, atomicWriteSync } from './atomic-write.mjs';
|
||||
|
||||
const META_FILENAME = '.backup-meta.json';
|
||||
const SENTINEL_FILENAME = '.rollback-in-progress';
|
||||
|
|
@ -84,39 +87,41 @@ export function backupDir(srcDir, backupRoot, opts = {}) {
|
|||
schema_version: 1,
|
||||
});
|
||||
|
||||
const restore = () => {
|
||||
// Scoped rollback: restore ONLY the relative paths (relative to srcDir) that the calling run
|
||||
// wrote this session. A file present in the backup is restored to its prior bytes atomically; a
|
||||
// file ABSENT from the backup was created this run, so rolling back means deleting it. Sibling
|
||||
// files a parallel session touched after this backup are never read or written, and there is no
|
||||
// window where srcDir is deleted. The sentinel is written before the first mutation and cleared
|
||||
// only on the success path — a throw mid-restore leaves it for detectStaleRollback().
|
||||
const restore = (relPaths) => {
|
||||
if (!Array.isArray(relPaths)) {
|
||||
throw new Error(
|
||||
"backupDir.restore: relPaths must be an array — restore is scoped to the run's own writes",
|
||||
);
|
||||
}
|
||||
const sentinelPath = join(backupRoot, SENTINEL_FILENAME);
|
||||
atomicWriteJson(sentinelPath, {
|
||||
backup_path: backupPath,
|
||||
src_dir: srcDir,
|
||||
rel_paths: relPaths,
|
||||
started_at: new Date().toISOString(),
|
||||
schema_version: 1,
|
||||
schema_version: 2,
|
||||
});
|
||||
try {
|
||||
rmSync(srcDir, {
|
||||
recursive: true,
|
||||
force: true,
|
||||
maxRetries: 3,
|
||||
retryDelay: 200,
|
||||
});
|
||||
cpSync(backupPath, srcDir, {
|
||||
recursive: true,
|
||||
force: true,
|
||||
preserveTimestamps: true,
|
||||
});
|
||||
// Remove the meta file we copied back into srcDir so srcDir is clean.
|
||||
const restoredMeta = join(srcDir, META_FILENAME);
|
||||
if (existsSync(restoredMeta)) {
|
||||
for (const rel of relPaths) {
|
||||
const from = join(backupPath, rel);
|
||||
const to = join(srcDir, rel);
|
||||
if (existsSync(from)) {
|
||||
mkdirSync(dirname(to), { recursive: true });
|
||||
atomicWriteSync(to, readFileSync(from)); // prior bytes, crash-safe (Buffer → byte-exact)
|
||||
} else if (existsSync(to)) {
|
||||
try {
|
||||
unlinkSync(restoredMeta);
|
||||
unlinkSync(to); // created this run — must not exist in the rolled-back state
|
||||
} catch {
|
||||
// best-effort
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
// Sentinel removed only on success path — leave it on throw so the
|
||||
// post-mortem detector can see the orphan.
|
||||
}
|
||||
// Success — clear the sentinel. On a throw above it is left behind for detectStaleRollback().
|
||||
try {
|
||||
unlinkSync(sentinelPath);
|
||||
} catch {
|
||||
|
|
|
|||
|
|
@ -18,7 +18,10 @@
|
|||
// - advisor allowlist: only the 4 non-advisor skills are walked; a target path that
|
||||
// matches /ms-ai-advisor/ is a hard throw (belt-and-suspenders on the pure fn).
|
||||
// - atomic: atomicWriteSync only, never the raw fs writer.
|
||||
// - backup: backupDir(root, backupRoot) before the first write; restore() retained.
|
||||
// - backup: backupDir(root, backupRoot) before the first write. Recovery contract — restore()
|
||||
// is SCOPED: it rolls back ONLY the files this run wrote, so a parallel session's writes to
|
||||
// sibling files survive; a stale rollback sentinel aborts the run; old backups are pruned
|
||||
// past retention after a successful batch.
|
||||
// - per-field idempotent: delegated to insertHeaderFields (skips set Type/Source) and
|
||||
// insertToc (skips a file that already hasToc / is small).
|
||||
// - post-write assertion: re-read each written file, assert parseTypeHeader (and, when a
|
||||
|
|
@ -41,7 +44,7 @@ import {
|
|||
} from './lib/transform.mjs';
|
||||
import { parseTypeHeader, parseSourceHeader } from './lib/kb-headers.mjs';
|
||||
import { atomicWriteSync } from './lib/atomic-write.mjs';
|
||||
import { backupDir } from './lib/backup.mjs';
|
||||
import { backupDir, detectStaleRollback, cleanupOldBackups } from './lib/backup.mjs';
|
||||
|
||||
// The 4 non-advisor skills, enumerated explicitly (NO shell brace-expansion). Advisor
|
||||
// (ms-ai-advisor) is deliberately absent — it is classified in the manifest but never
|
||||
|
|
@ -170,16 +173,30 @@ export function migrateCorpus({ root, backupRoot, manifest, write = false }) {
|
|||
return { root, write, backupPath: null, restore: null, results, counts };
|
||||
}
|
||||
|
||||
// ONE backup before the first write — restore() undoes the whole batch.
|
||||
const { backupPath, restore } = backupDir(skillsDir, backupRoot);
|
||||
// A stale rollback sentinel means a prior run crashed mid-restore and the tree may be
|
||||
// inconsistent — refuse to write over it; the operator must recover and clear it first.
|
||||
if (detectStaleRollback(backupRoot)) {
|
||||
throw new Error(
|
||||
`migrateCorpus: a stale rollback sentinel is present under ${backupRoot} — a prior run ` +
|
||||
`crashed mid-restore. Recover the corpus and clear .rollback-in-progress before rerunning.`,
|
||||
);
|
||||
}
|
||||
|
||||
// ONE backup before the first write. restore() rolls back ONLY the files THIS run wrote
|
||||
// (scoped) — a parallel session's writes to sibling files are never touched.
|
||||
const { backupPath, retentionDays, restore: restoreFiles } = backupDir(skillsDir, backupRoot);
|
||||
const writtenRel = [];
|
||||
const restore = () => restoreFiles(writtenRel);
|
||||
|
||||
for (const r of changed) {
|
||||
const rel = relative(skillsDir, r.full).split(sep).join('/');
|
||||
atomicWriteSync(r.full, r.content);
|
||||
writtenRel.push(rel);
|
||||
const written = readFileSync(r.full, 'utf8');
|
||||
const typeOk = !r.expectType || parseTypeHeader(written) !== null;
|
||||
const sourceOk = !r.expectSource || parseSourceHeader(written) !== null;
|
||||
if (!typeOk || !sourceOk) {
|
||||
restore(); // roll the whole batch back — never leave a partial corpus
|
||||
restore(); // roll back only this run's own writes — never leave a partial corpus
|
||||
throw new Error(
|
||||
`migrateCorpus: post-write header truncated for ${r.relpath} ` +
|
||||
`(inserted field fell past the ${500}-byte scan window; corpus restored from backup)`,
|
||||
|
|
@ -189,6 +206,9 @@ export function migrateCorpus({ root, backupRoot, manifest, write = false }) {
|
|||
counts.written += 1;
|
||||
}
|
||||
|
||||
// Successful batch — prune backups past retention (best-effort hygiene).
|
||||
cleanupOldBackups(backupRoot, retentionDays);
|
||||
|
||||
return { root, write, backupPath, restore, results, counts };
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,11 +19,15 @@
|
|||
// creation-vs-modified date pair) → carved out to a later dedup unit, and the collision-guard aborts on
|
||||
// them regardless. 8 further occurrences are body/list/placeholder and are never in scope.
|
||||
//
|
||||
// Recovery contract: writes are crash-safe (atomicWriteSync tmp+rename — a reader sees the old
|
||||
// file or the new one, never a partial); an interrupted run is recovered by re-running (idempotent).
|
||||
//
|
||||
// Usage: node scripts/kb-update/relabel-dato.mjs [--dry]
|
||||
import { readFileSync, writeFileSync, existsSync, realpathSync } from 'node:fs';
|
||||
import { readFileSync, existsSync, realpathSync } from 'node:fs';
|
||||
import { join, dirname } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { relabelHeaderDialect } from './relabel-dialect.mjs';
|
||||
import { atomicWriteSync } from './lib/atomic-write.mjs';
|
||||
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||
const PLUGIN_ROOT = join(__dirname, '..', '..');
|
||||
|
|
@ -125,7 +129,7 @@ function run({ dry }) {
|
|||
}
|
||||
return;
|
||||
}
|
||||
for (const p of planned) writeFileSync(join(PLUGIN_ROOT, p.rel), p.out);
|
||||
for (const p of planned) atomicWriteSync(join(PLUGIN_ROOT, p.rel), p.out);
|
||||
console.log(`\nWrote ${planned.length} files.`);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,10 +18,14 @@
|
|||
// label token swapped, everything else byte-identical). Idempotent: a file with no norsk header
|
||||
// label is skipped, so a re-run is a no-op. Aborts and writes nothing on any drift or invariant breach.
|
||||
//
|
||||
// Recovery contract: writes are crash-safe (atomicWriteSync tmp+rename — a reader sees the old
|
||||
// file or the new one, never a partial); an interrupted run is recovered by re-running (idempotent).
|
||||
//
|
||||
// Usage: node scripts/kb-update/relabel-dialect.mjs [--dry]
|
||||
import { readFileSync, writeFileSync, existsSync, realpathSync } from 'node:fs';
|
||||
import { readFileSync, existsSync, realpathSync } from 'node:fs';
|
||||
import { join, dirname } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { atomicWriteSync } from './lib/atomic-write.mjs';
|
||||
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||
const PLUGIN_ROOT = join(__dirname, '..', '..');
|
||||
|
|
@ -180,7 +184,7 @@ function run({ dry }) {
|
|||
}
|
||||
return;
|
||||
}
|
||||
for (const p of planned) writeFileSync(join(PLUGIN_ROOT, p.rel), p.out);
|
||||
for (const p of planned) atomicWriteSync(join(PLUGIN_ROOT, p.rel), p.out);
|
||||
console.log(`\nWrote ${planned.length} files.`);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue