Files
memind/scripts/verify-public-finish-sync-runtime.mjs
T
john 98721371a4 fix(mindspace): edit_file 落盘、Finish 聊天 merge 与回归守卫
- finish-sync 支持 edit_file 覆盖 public HTML
- Finish 同步 merge 本地流式消息,剥离 agent 内部前缀
- 新增 verify:mindspace-publish-guards 与 AGENTS.md 跨工具说明
- 发版脚本接入回归门禁;103 runtime 发布含备份回退

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-30 00:27:15 +08:00

82 lines
2.4 KiB
JavaScript

import assert from 'node:assert/strict';
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import {
hasRecentOwnPublicHtmlReference,
materializeMissingPublicHtmlWrites,
} from '../mindspace-public-finish-sync.mjs';
const root = path.resolve(new URL('..', import.meta.url).pathname);
const runtimeServer = path.join(root, '.runtime', 'portal', 'server.mjs');
const currentUser = { id: 'a6fb1e97-2b0f-447b-b138-4561d8e5c53e', username: 'john' };
const toolRequestOnlyMessages = [
{
role: 'assistant',
content: [
{
type: 'toolRequest',
toolCall: {
value: {
name: 'write',
arguments: {
path: 'public/guarded-release.html',
content: '<!doctype html><title>Guarded release</title>',
},
},
},
},
],
},
...Array.from({ length: 12 }, (_, index) => ({
role: index % 2 === 0 ? 'assistant' : 'user',
content: [{ type: 'text', text: `validation step ${index + 1}` }],
})),
];
assert.equal(
hasRecentOwnPublicHtmlReference(toolRequestOnlyMessages, currentUser),
true,
'finish sync must detect textless write tool requests beyond the old eight-message window',
);
const publishDir = fs.mkdtempSync(path.join(os.tmpdir(), 'public-finish-release-guard-'));
try {
const result = materializeMissingPublicHtmlWrites({
messages: toolRequestOnlyMessages,
publishDir,
});
assert.deepEqual(result.materialized, ['public/guarded-release.html']);
assert.equal(
fs.readFileSync(path.join(publishDir, 'public/guarded-release.html'), 'utf8'),
'<!doctype html><title>Guarded release</title>',
);
} finally {
fs.rmSync(publishDir, { recursive: true, force: true });
}
if (!fs.existsSync(runtimeServer)) {
throw new Error(`runtime server bundle is missing: ${runtimeServer}`);
}
const runtimeSource = fs.readFileSync(runtimeServer, 'utf8');
const requiredRuntimeSnippets = [
'normalizedName === "write"',
'normalizedName.endsWith("__write")',
'normalizedName === "edit_file"',
'applyPublicHtmlEdit',
'recentCount = 80',
'if (extractPublicHtmlWriteArtifacts([message], { publishDir }).length > 0) {',
];
for (const snippet of requiredRuntimeSnippets) {
assert.ok(
runtimeSource.includes(snippet),
`runtime server bundle is missing public finish sync guard: ${snippet}`,
);
}
console.log('public finish sync runtime guard ok');