804f13bc04
Reject /api/page-data/ legacy passthrough, verify live API before send, and resolve delivery links to Portal (8081) instead of Vite (5173). Add local repair/verify scripts for daily-register Page Data flow. Co-authored-by: Cursor <cursoragent@cursor.com>
71 lines
2.2 KiB
JavaScript
71 lines
2.2 KiB
JavaScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import {
|
|
assertPolicyMatchesHtmlDatasets,
|
|
buildPageDataPolicyDatasetsFromRegistry,
|
|
detectPageDataDatasetUsageFromHtml,
|
|
htmlUsesForbiddenLegacyPageDataApi,
|
|
htmlUsesPageDataApi,
|
|
} from './page-data-html-detect.mjs';
|
|
|
|
test('htmlUsesForbiddenLegacyPageDataApi detects /api/page-data passthrough', () => {
|
|
const html = `fetch('/api/page-data/daily_todo', { method: 'POST' })`;
|
|
assert.equal(htmlUsesForbiddenLegacyPageDataApi(html), true);
|
|
assert.equal(htmlUsesPageDataApi(html), true);
|
|
assert.equal(detectPageDataDatasetUsageFromHtml(html).size, 0);
|
|
});
|
|
|
|
test('detectPageDataDatasetUsageFromHtml finds insert and read datasets', () => {
|
|
const html = `
|
|
await c.insertRow('tkmind_exp_survey', { satisfaction: '满意' });
|
|
await c.listRows('tkmind_exp_survey', { limit: 10 });
|
|
`;
|
|
const usage = detectPageDataDatasetUsageFromHtml(html);
|
|
assert.equal(usage.size, 1);
|
|
assert.deepEqual(usage.get('tkmind_exp_survey'), { insert: true, read: true });
|
|
});
|
|
|
|
test('detectPageDataDatasetUsageFromHtml resolves dataset constants', () => {
|
|
const html = `
|
|
const DATASET = 'reading_survey';
|
|
await client.listRows(DATASET, { limit: 500 });
|
|
`;
|
|
const usage = detectPageDataDatasetUsageFromHtml(html);
|
|
assert.deepEqual(usage.get('reading_survey'), { read: true });
|
|
});
|
|
|
|
test('assertPolicyMatchesHtmlDatasets rejects mismatched dataset names', () => {
|
|
const html = `await c.insertRow('tkmind_exp_survey', {});`;
|
|
assert.throws(
|
|
() =>
|
|
assertPolicyMatchesHtmlDatasets(html, {
|
|
experience_survey_responses: { insert: true },
|
|
}),
|
|
/不一致/,
|
|
);
|
|
});
|
|
|
|
test('buildPageDataPolicyDatasetsFromRegistry infers insert-only policy', () => {
|
|
const html = `await c.insertRow('survey_responses', { q1: 'a' });`;
|
|
const datasets = buildPageDataPolicyDatasetsFromRegistry({
|
|
html,
|
|
registryDatasets: [
|
|
{
|
|
name: 'survey_responses',
|
|
columns: {
|
|
insert: ['q1'],
|
|
read: ['id', 'q1', 'created_at'],
|
|
},
|
|
},
|
|
],
|
|
});
|
|
assert.deepEqual(datasets.survey_responses, {
|
|
insert: true,
|
|
read: false,
|
|
update: false,
|
|
softDelete: false,
|
|
hardDelete: false,
|
|
columns: { insert: ['q1'] },
|
|
});
|
|
});
|