fix(qmd): write index.yml atomically

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Julian lechnerandClaude Opus 5.5 committed 2026-10-08 12:42:40 +02:00
1 parent ced6d8f119
commit abface2293
3 files changed
+23 -10

No files matched your search

+11 -2
View File
@@ -1,10 +1,10 @@
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { mkdirSync, mkdtempSync, writeFileSync } from 'node:fs';
import { mkdirSync, mkdtempSync, readdirSync, readFileSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import * as YAML from './fixtures/yaml-shim.mjs';
import { collectionName, deviceEnv, idleMinutes, qmdConfigPath, writePrivateJson, readJson, runQmdCli, MODELS } from '../../shared/qmd/qmd-lib.mjs';
import { collectionName, deviceEnv, idleMinutes, qmdConfigPath, writePrivateJson, writeTextAtomic, readJson, runQmdCli, MODELS } from '../../shared/qmd/qmd-lib.mjs';
import { setModels, unsetModels, previousModels, restoreModels } from '../../shared/qmd/qmd-config.mjs';
test('collection name is stable, prefixed, and path-safe', () => {
@@ -93,3 +93,12 @@ test('restoreModels writes the previous block back and keeps comments and other
assert.match(restored, /collections:/);
assert.doesNotMatch(restored, /Qwen/);
});
test('writeTextAtomic replaces the file through a temp file in the same directory', () => {
const dir = join(mkdtempSync(join(tmpdir(), 'qmd-lib-')), 'cfg');
const file = join(dir, 'index.yml');
writeTextAtomic(file, 'a: 1\n');
writeTextAtomic(file, 'b: 2\n');
assert.equal(readFileSync(file, 'utf8'), 'b: 2\n');
assert.deepEqual(readdirSync(dir), ['index.yml']);
});