73b308af0a
Prevent false-positive Finish Guard passes and sync-created fake bindings by assessing publication, policy, dataset, injection, and insert smoke before H5 delivery. Co-authored-by: Cursor <cursoragent@cursor.com>
113 lines
3.4 KiB
JavaScript
113 lines
3.4 KiB
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* 为已知破损问卷补注册 dataset(表已存在但 __page_data_datasets 未登记的场景)。
|
|
*/
|
|
import path from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
import { loadH5Environment } from './load-env.mjs';
|
|
import { createUserDataSpaceService } from '../user-data-space-service.mjs';
|
|
|
|
const repoRoot = path.join(path.dirname(fileURLToPath(import.meta.url)), '..');
|
|
loadH5Environment(import.meta.dirname);
|
|
|
|
const PRESETS = {
|
|
'a70ff537-8908-486e-9b6c-042e07cc25db': [
|
|
{
|
|
name: 'company_suggestions',
|
|
table: 'company_suggestions',
|
|
description: '公司建议问卷调查',
|
|
actions: ['read', 'insert'],
|
|
columns: {
|
|
read: [
|
|
'id',
|
|
'department',
|
|
'q_work_env',
|
|
'q_management',
|
|
'q_teamwork',
|
|
'q_salary_welfare',
|
|
'q_dev_opportunity',
|
|
'q_other_suggestion',
|
|
'overall_rating',
|
|
'created_at',
|
|
],
|
|
insert: [
|
|
'department',
|
|
'q_work_env',
|
|
'q_management',
|
|
'q_teamwork',
|
|
'q_salary_welfare',
|
|
'q_dev_opportunity',
|
|
'q_other_suggestion',
|
|
'overall_rating',
|
|
],
|
|
},
|
|
},
|
|
{
|
|
name: 'diet_survey',
|
|
table: 'diet_survey',
|
|
description: '儿童饮食偏好调查',
|
|
actions: ['read', 'insert'],
|
|
columns: {
|
|
read: ['id', 'child_age', 'veggie_habit', 'snack_type', 'created_at'],
|
|
insert: ['child_age', 'veggie_habit', 'snack_type'],
|
|
},
|
|
},
|
|
],
|
|
'a6fb1e97-2b0f-447b-b138-4561d8e5c53e': [
|
|
{
|
|
name: 'dining_survey',
|
|
table: 'dining_survey',
|
|
description: '餐饮偏好调查问卷',
|
|
sql: `CREATE TABLE IF NOT EXISTS dining_survey (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
q1_frequency TEXT NOT NULL DEFAULT '',
|
|
q2_priority TEXT NOT NULL DEFAULT '',
|
|
q3_cuisine TEXT NOT NULL DEFAULT '',
|
|
created_at TEXT NOT NULL DEFAULT (datetime('now', '+8 hours'))
|
|
);`,
|
|
actions: ['read', 'insert'],
|
|
columns: {
|
|
read: ['id', 'q1_frequency', 'q2_priority', 'q3_cuisine', 'created_at'],
|
|
insert: ['q1_frequency', 'q2_priority', 'q3_cuisine'],
|
|
},
|
|
},
|
|
],
|
|
};
|
|
|
|
async function main() {
|
|
const userIds = process.argv.slice(2);
|
|
const targets = userIds.length ? userIds : Object.keys(PRESETS);
|
|
for (const userId of targets) {
|
|
const presets = PRESETS[userId];
|
|
if (!presets) {
|
|
console.warn(`跳过 ${userId}:无 preset`);
|
|
continue;
|
|
}
|
|
const workspaceRoot = path.join(repoRoot, 'MindSpace', userId);
|
|
const dataSpace = createUserDataSpaceService({ workspaceRoot });
|
|
for (const preset of presets) {
|
|
if (preset.sql) {
|
|
await dataSpace.executeSql(preset.sql);
|
|
console.log(`[${userId}] 已确保表 ${preset.table}`);
|
|
}
|
|
if (!dataSpace.getDataset(preset.name)) {
|
|
await dataSpace.upsertDataset({
|
|
name: preset.name,
|
|
table: preset.table,
|
|
description: preset.description,
|
|
actions: preset.actions,
|
|
columns: preset.columns,
|
|
});
|
|
console.log(`[${userId}] 已注册 dataset ${preset.name}`);
|
|
} else {
|
|
console.log(`[${userId}] dataset ${preset.name} 已存在`);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
main().catch((error) => {
|
|
console.error(error instanceof Error ? error.stack ?? error.message : error);
|
|
process.exit(1);
|
|
});
|