fix: retain installation receipts without a size ceiling

This commit is contained in:
Agent Workbench Dev
2026-11-06 08:35:07 +08:00
parent e86f576ff2
commit 5acb657157
8 changed files with 69 additions and 8 deletions
+22 -4
View File
@@ -6,6 +6,7 @@ import assert from 'node:assert/strict';
import { execFile } from 'node:child_process';
import { promisify } from 'node:util';
import { randomUUID, createHash } from 'node:crypto';
import { DatabaseSync } from 'node:sqlite';
import { buildWindowsInstaller } from './build-installer.mjs';
import { publicSnapshot, compareOriginalState } from './retained-host-state.mjs';
import { HostController } from '../src/core/desktop/host-controller.mjs';
@@ -25,11 +26,15 @@ const previous = read(path.join(previousRoot, 'MANIFEST.json')), candidate = rea
const [major, minor, patch] = candidate.version.split('.').map(Number);
assert.ok(patch > 0); assert.equal(previous.version, `${major}.${minor}.${patch - 1}`);
assert.equal(previous.kind, 'portable'); assert.equal(candidate.kind, 'portable');
const root = path.resolve('.qa', 'previous-patch-install-' + randomUUID());
fs.mkdirSync(path.resolve('.qa'), { recursive: true });
const root = fs.mkdtempSync(path.resolve('.qa', 'pv-'));
const installRoot = path.join(root, 'program'), dataRoot = path.join(root, 'user-data'), appId = randomUUID();
fs.mkdirSync(root, { recursive: true });
const save = (name, value) => fs.writeFileSync(path.join(root, name), JSON.stringify(value, null, 2) + '\n', { flag: 'wx' });
const hash = value => createHash('sha256').update(value).digest('hex');
const maximumInstalledPath = Math.max(...previous.files.map(row => path.join(installRoot, 'versions', path.basename(previousRoot), row.path).length),
...candidate.files.map(row => path.join(installRoot, 'versions', path.basename(candidateRoot), row.path).length));
assert.ok(maximumInstalledPath < 250, 'Use a shorter workspace path for this Windows installer test.');
save('path-preflight.json', { maximumInstalledPath, installRoot });
const run = promisify(execFile), env = projectEnvironment();
const reserve = net.createServer(); await new Promise(resolve => reserve.listen(0, '127.0.0.1', resolve));
const port = reserve.address().port; await new Promise(resolve => reserve.close(resolve));
@@ -68,7 +73,16 @@ try {
const initial = Buffer.from('\uFEFF# Owned previous-patch source\r\n'); fs.writeFileSync(path.join(projectRoot, 'README.md'), initial);
const project = await controller.api('/projects', { method: 'POST', input: { root: projectRoot } });
assert.equal(project.root, projectRoot);
await controller.api('/sessions', { method: 'POST', input: { projectId: project.id } });
const session = await controller.api('/sessions', { method: 'POST', input: { projectId: project.id } });
const database = new DatabaseSync(path.join(dataRoot, 'workbench.sqlite'));
try {
database.exec('BEGIN IMMEDIATE');
database.prepare(`WITH RECURSIVE n(v) AS (VALUES(1) UNION ALL SELECT v+1 FROM n WHERE v<35000)
INSERT INTO events(id,session_id,project_id,type,revision,created_at,payload)
SELECT 'owned-large-history-'||v,?,?,'owned.large_history',0,'2026-11-05T00:00:00.000Z','{}' FROM n`).run(session.id, project.id);
database.exec("INSERT INTO outbox(seq) SELECT seq FROM events WHERE type='owned.large_history'; COMMIT");
} finally { database.close(); }
save('large-history-fixture.json', { events: 35000, outbox: 35000, synthetic: true });
await controller.api('/config', { method: 'POST', input: { mode: 'compatible', model: 'owned-previous-patch-model',
baseUrl: 'http://127.0.0.1:' + model.address().port + '/v1', apiKey: key } });
await controller.api('/config/models', { method: 'POST', input: {} }); assert.equal(authenticated, 1);
@@ -87,8 +101,12 @@ try {
assert.equal(pointer.revision, pointerBefore.revision + 1); assert.equal(pointer.previous.version, previous.version);
assert.equal(pointer.active.version, candidate.version); assert.deepEqual(fs.readFileSync(path.join(projectRoot, 'README.md')), initial);
await controller.api('/config/models', { method: 'POST', input: {} }); assert.equal(authenticated, 2);
const operationFile = fs.readdirSync(path.join(installRoot, '.installation')).filter(name => /^operation-.*\.json$/.test(name))
.map(name => path.join(installRoot, '.installation', name)).find(file => read(file).candidate.version === candidate.version);
assert.ok(operationFile); assert.equal(read(operationFile).state, 'activated');
const receiptBytes = fs.statSync(operationFile).size; assert.ok(receiptBytes > 4 * 1024 * 1024);
save('state-updated.json', after); save('pointer-updated.json', pointer);
passed(stage, { ...receipt, from: previous.version, to: after.version, pid: after.pid, instanceId: original.instanceId, retention, authenticated });
passed(stage, { ...receipt, from: previous.version, to: after.version, pid: after.pid, instanceId: original.instanceId, retention, authenticated, receiptBytes });
stage = 'owned program uninstall preserves data';
await controller.stop(); controller = null;
const baseline = snapshotPersistentData(dataRoot), uninstallLog = path.join(root, 'uninstall.log');