remote-startup-profile.ts 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import { mkdir, readFile, writeFile } from "node:fs/promises";
  2. import { join } from "node:path";
  3. import { onboardingRecordFileSchema } from "@zcode/shared";
  4. /** 远程场景从已完成引导的隔离账号开始;导航专项仍走自己的真实引导链。 */
  5. export async function seedRemoteOnboardingFixture(options: {
  6. enabled: boolean;
  7. specs: readonly string[];
  8. appConfigDir: string;
  9. userId: string;
  10. }): Promise<void> {
  11. if (
  12. !options.enabled ||
  13. options.specs.some((spec) =>
  14. spec.endsWith("conversation-session-rpn-project-navigation.test.ts"),
  15. )
  16. )
  17. return;
  18. // 只填 setting.json 不足以完成新引导,产品按独立记录及当前 userId 判定。
  19. // 保留匿名条目供 live 账号登录认领,不伪造真实账号或绕开服务的认领规则。
  20. const record = onboardingRecordFileSchema.parse({
  21. version: 1,
  22. deviceMid: "zcode-remote-e2e-device",
  23. entries: [options.userId, null].map((userId) => ({
  24. userId,
  25. occupation: "developer",
  26. interfaceMode: "coding",
  27. memoryEnabled: false,
  28. proactiveSuggestionsEnabled: false,
  29. completedAt: new Date().toISOString(),
  30. uploadState: "pending",
  31. })),
  32. });
  33. await mkdir(options.appConfigDir, { recursive: true });
  34. await writeFile(
  35. join(options.appConfigDir, "onboarding-record.json"),
  36. JSON.stringify(record, null, 2),
  37. );
  38. const settingsPath = join(options.appConfigDir, "setting.json");
  39. const settings = await readFile(settingsPath, "utf8").then(
  40. (contents) => JSON.parse(contents),
  41. (error: NodeJS.ErrnoException) => {
  42. if (error.code !== "ENOENT") throw error;
  43. return {};
  44. },
  45. );
  46. await writeFile(
  47. settingsPath,
  48. JSON.stringify(
  49. {
  50. ...settings,
  51. onboardingOccupation: "developer",
  52. memoryEnabled: false,
  53. proactiveSuggestionsEnabled: false,
  54. },
  55. null,
  56. 2,
  57. ),
  58. );
  59. }