fix(page-data): scope finish guard to current delivery

This commit is contained in:
john
2026-07-13 06:56:27 +08:00
parent cdeb24ba92
commit 249b0697cb
3 changed files with 84 additions and 12 deletions
+48
View File
@@ -9,12 +9,15 @@ import {
collectPageDataDeliveryArtifacts,
evaluatePageDataFinishGuard,
evaluatePageDataHtmlContent,
extractRecentPageDataBindTargets,
extractRecentPageDataHtmlWrites,
inferPageDataBindAccessMode,
maybeAutoBindPageDataHtmlPages,
rewritePageDataDeliveryLinks,
shouldRetryPageDataCollectReply,
} from './mindspace-page-data-finish-guard.mjs';
import { writePageAccessPolicy } from './page-data-policy-store.mjs';
import { createUserDataSpaceService } from './user-data-space-service.mjs';
const SURVEY_HTML = `<!doctype html><html><head><title>问卷</title></head><body>
<script src="/assets/page-data-client.js"></script>
@@ -67,6 +70,51 @@ test('evaluatePageDataFinishGuard detects unbound page data html', () => {
}
});
test('finish guard ignores unrelated historical broken Page Data html', async () => {
const publishDir = fs.mkdtempSync(path.join(os.tmpdir(), 'page-data-guard-history-'));
try {
fs.mkdirSync(path.join(publishDir, 'public'), { recursive: true });
fs.writeFileSync(path.join(publishDir, 'public', 'historical-admin.html'), BAD_SURVEY_HTML, 'utf8');
fs.writeFileSync(path.join(publishDir, 'public', 'current-survey.html'), SURVEY_HTML, 'utf8');
const dataSpace = createUserDataSpaceService({ workspaceRoot: publishDir });
await dataSpace.executeSql('CREATE TABLE diet_survey (id INTEGER PRIMARY KEY AUTOINCREMENT);');
await dataSpace.upsertDataset({
name: 'diet_survey',
table: 'diet_survey',
actions: ['read', 'insert'],
columns: { read: ['id'], insert: [] },
});
writePageAccessPolicy(publishDir, {
pageId: 'current-page',
ownerUserId: 'user-1',
accessMode: 'public',
datasets: { diet_survey: { insert: true, read: false, columns: { insert: [] } } },
});
const evaluation = evaluatePageDataFinishGuard({
publishDir,
agentText: '调查问卷和后台',
messages: [{ content: [{ type: 'toolRequest', toolCall: { value: {
name: 'sandbox-fs__write_file',
arguments: { path: 'public/current-survey.html' },
} } }] }],
});
assert.deepEqual(evaluation.relevantFiles.map((file) => file.relativePath), ['public/current-survey.html']);
assert.deepEqual(evaluation.htmlIssues, []);
assert.deepEqual(evaluation.unboundFiles, []);
} finally {
fs.rmSync(publishDir, { recursive: true, force: true });
}
});
test('recent Page Data target extraction supports namespaced writes and bind-only delivery', () => {
const messages = [{ content: [
{ type: 'toolRequest', toolCall: { value: { name: 'sandbox-fs__write_file', arguments: { path: 'public/form.html' } } } },
{ type: 'toolRequest', toolCall: { value: { name: 'sandbox-fs__private_data_bind_workspace_page', arguments: { relativePath: 'public/form-admin.html' } } } },
] }];
assert.deepEqual(extractRecentPageDataHtmlWrites(messages), ['public/form.html']);
assert.deepEqual(extractRecentPageDataBindTargets(messages), ['public/form-admin.html']);
});
test('shouldRetryPageDataCollectReply retries when localStorage fallback exists', () => {
const publishDir = fs.mkdtempSync(path.join(os.tmpdir(), 'page-data-guard-retry-'));
try {