Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 

49 linhas
3.0 KiB

  1. import fs from 'node:fs';
  2. import path from 'node:path';
  3. import crypto from 'node:crypto';
  4. import assert from 'node:assert/strict';
  5. import { fileURLToPath } from 'node:url';
  6. import { login, root } from './role-permissions-live.mjs';
  7. export { login };
  8. export async function call(endpoint, token, body, method = body === undefined ? 'GET' : 'POST') {
  9. const response = await fetch(`http://127.0.0.1:6180/api/${endpoint}`, {
  10. method, headers: { 'Content-Type': 'application/json', ...(token ? { Authorization: `Bearer ${token}` } : {}) },
  11. body: body === undefined ? undefined : JSON.stringify(body), signal: AbortSignal.timeout(120000),
  12. });
  13. const value = await response.json();
  14. return { status: response.status, code: value.code, data: value.data, message: value.message };
  15. }
  16. export const report = path.join(root, 'ute2e/reports/model-editor-closure-20260906');
  17. export const work = path.resolve(root, '../.codex-tmp/model-closure-20260906');
  18. export const fixturePath = path.join(work, 'fixtures.json');
  19. fs.mkdirSync(report, { recursive: true }); fs.mkdirSync(work, { recursive: true });
  20. export const fixture = () => JSON.parse(fs.readFileSync(fixturePath, 'utf8'));
  21. export const writeFixture = value => fs.writeFileSync(fixturePath, JSON.stringify(value, null, 2));
  22. const hash = value => crypto.createHash('sha256').update(JSON.stringify(value)).digest('hex');
  23. async function prepare() {
  24. if (fs.existsSync(fixturePath) && !fixture().cleanedAt && !process.argv.includes('--resume')) throw new Error('This run already has fixtures; reuse them or clean up first');
  25. const session = await login('root');
  26. const data = process.argv.includes('--resume') ? fixture() : { createdAt: new Date().toISOString(), models: {}, extraProjectIds: [], originals: {} };
  27. writeFixture(data);
  28. try {
  29. for (const [key, id, name] of [['fox', '157', '闭环验收-狐狸-20260906'], ['truck', '156', '闭环验收-牛奶卡车-20260906']]) {
  30. if (data.models[key]) continue;
  31. const original = await call(`tran/v1/content/projects/${id}`, session.accessToken);
  32. assert.equal(original.status, 200);
  33. data.originals[key] = { id, name: original.data.project.name, version: original.data.project.version, hash: hash(original.data) };
  34. fs.writeFileSync(path.join(work, `original-${key}.json`), JSON.stringify(original.data, null, 2));
  35. writeFixture(data);
  36. const copy = await call(`tran/v1/content/projects/${id}/copy`, session.accessToken, { name, version: original.data.project.version });
  37. assert.equal(copy.status, 200, `Copy ${key}: ${copy.message}`);
  38. assert.ok(copy.data.project.id);
  39. data.models[key] = { id: copy.data.project.id, name, code: copy.data.project.code };
  40. writeFixture(data);
  41. }
  42. console.log(JSON.stringify({ fixturesReady: true, models: data.models }));
  43. } finally { await call('auth/v1/auth/logout', session.accessToken, {}).catch(() => {}); }
  44. }
  45. if (process.argv[1] === fileURLToPath(import.meta.url)) prepare().catch(error => { console.error(error.message); process.exitCode = 1; });