@superblocksteam/sdk 2.0.153-next.2 → 2.0.153

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (26) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/dist/cli-replacement/dev-s3-restore.test.mjs +0 -1
  3. package/dist/cli-replacement/dev-s3-restore.test.mjs.map +1 -1
  4. package/dist/cli-replacement/dev-startup-git-before-dbfs-order.test.mjs +7 -59
  5. package/dist/cli-replacement/dev-startup-git-before-dbfs-order.test.mjs.map +1 -1
  6. package/dist/cli-replacement/dev.d.mts.map +1 -1
  7. package/dist/cli-replacement/dev.mjs +1 -35
  8. package/dist/cli-replacement/dev.mjs.map +1 -1
  9. package/dist/cli-replacement/install-packages.npm-registry.test.mjs +0 -30
  10. package/dist/cli-replacement/install-packages.npm-registry.test.mjs.map +1 -1
  11. package/package.json +6 -6
  12. package/src/cli-replacement/dev-s3-restore.test.mts +0 -1
  13. package/src/cli-replacement/dev-startup-git-before-dbfs-order.test.mts +58 -129
  14. package/src/cli-replacement/dev.mts +0 -42
  15. package/src/cli-replacement/install-packages.npm-registry.test.mts +0 -43
  16. package/tsconfig.tsbuildinfo +1 -1
  17. package/dist/cli-replacement/npm-install-cpu.d.mts +0 -15
  18. package/dist/cli-replacement/npm-install-cpu.d.mts.map +0 -1
  19. package/dist/cli-replacement/npm-install-cpu.mjs +0 -79
  20. package/dist/cli-replacement/npm-install-cpu.mjs.map +0 -1
  21. package/dist/cli-replacement/npm-install-cpu.test.d.mts +0 -2
  22. package/dist/cli-replacement/npm-install-cpu.test.d.mts.map +0 -1
  23. package/dist/cli-replacement/npm-install-cpu.test.mjs +0 -84
  24. package/dist/cli-replacement/npm-install-cpu.test.mjs.map +0 -1
  25. package/src/cli-replacement/npm-install-cpu.mts +0 -86
  26. package/src/cli-replacement/npm-install-cpu.test.mts +0 -131
@@ -121,7 +121,7 @@ vi.mock("@superblocksteam/vite-plugin-file-sync/ai-service", () => ({
121
121
  removeIntegrationCache = vi.fn(async () => undefined);
122
122
  remediateDeclaredDependencies = vi.fn(async () => undefined);
123
123
  chatSessionStore = { invalidateCache: vi.fn() };
124
- getNpmRegistryClient = mockGetNpmRegistryClient;
124
+ getNpmRegistryClient = vi.fn(() => undefined);
125
125
  },
126
126
  AiServiceFeatureFlags: class {
127
127
  static create = vi.fn(() => ({}));
@@ -136,84 +136,63 @@ vi.mock("@superblocksteam/vite-plugin-file-sync/ai-service", () => ({
136
136
 
137
137
  vi.mock("@superblocksteam/vite-plugin-file-sync/npm-registry", () => ({
138
138
  shouldIgnoreInstallScripts: vi.fn(() => false),
139
- maybeWriteNpmrcForDir: vi.fn(async () => {
140
- // Delay before the log push so this test fails if syncHomeNpmrc is
141
- // fire-and-forget (initiation order alone would still look correct).
142
- await new Promise((resolve) => setTimeout(resolve, 5));
143
- startupOpLog.push("project-npmrc:maybeWriteNpmrcForDir");
144
- }),
145
139
  }));
146
140
 
147
- const { startupOpLog, buildMockGitService, mockGetNpmRegistryClient } =
148
- vi.hoisted(() => {
149
- const startupOpLog: string[] = [];
150
- const mockGetNpmRegistryClient = vi.fn(
151
- ():
152
- | {
153
- getConfig: ReturnType<typeof vi.fn>;
154
- organizationId: string;
155
- }
156
- | undefined => ({
157
- organizationId: "org-1",
158
- getConfig: vi.fn(async () => ({
159
- source: "not-configured",
160
- config: { configured: false },
161
- })),
141
+ const { startupOpLog, buildMockGitService } = vi.hoisted(() => {
142
+ const startupOpLog: string[] = [];
143
+ function buildMockGitService(cwd: string) {
144
+ return {
145
+ workDir: cwd,
146
+ configure: vi.fn(async () => {
147
+ startupOpLog.push("git:configure");
162
148
  }),
163
- );
164
- function buildMockGitService(cwd: string) {
165
- return {
166
- workDir: cwd,
167
- configure: vi.fn(async () => {
168
- startupOpLog.push("git:configure");
169
- }),
170
- init: vi.fn(async () => {
171
- startupOpLog.push("git:init");
172
- }),
173
- addRemote: vi.fn(async () => {
174
- startupOpLog.push("git:addRemote");
175
- }),
176
- fetch: vi.fn(async () => {
177
- startupOpLog.push("git:fetch");
178
- }),
179
- raw: vi.fn(async (args: string | string[]) => {
180
- const argv = Array.isArray(args) ? args : [args];
181
- startupOpLog.push(`git:raw:${argv.join(" ")}`);
182
- if (argv[0] === "ls-remote" && argv.includes("__live__")) {
183
- return "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef\trefs/heads/__live__\n";
184
- }
185
- if (argv[0] === "branch" && argv.includes("--show-current")) {
186
- return "__live__\n";
187
- }
188
- if (argv[0] === "commit") {
189
- return "";
190
- }
149
+ init: vi.fn(async () => {
150
+ startupOpLog.push("git:init");
151
+ }),
152
+ addRemote: vi.fn(async () => {
153
+ startupOpLog.push("git:addRemote");
154
+ }),
155
+ fetch: vi.fn(async () => {
156
+ startupOpLog.push("git:fetch");
157
+ }),
158
+ raw: vi.fn(async (args: string | string[]) => {
159
+ const argv = Array.isArray(args) ? args : [args];
160
+ startupOpLog.push(`git:raw:${argv.join(" ")}`);
161
+ if (argv[0] === "ls-remote" && argv.includes("__live__")) {
162
+ return "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef\trefs/heads/__live__\n";
163
+ }
164
+ if (argv[0] === "branch" && argv.includes("--show-current")) {
165
+ return "__live__\n";
166
+ }
167
+ if (argv[0] === "commit") {
191
168
  return "";
192
- }),
193
- push: vi.fn(async () => {
194
- startupOpLog.push("git:push");
195
- }),
196
- getDefaultBranch: vi.fn(async () => "main"),
197
- getRemotes: vi.fn(async () => [
198
- { name: "origin", refs: { fetch: "https://example.test/repo.git" } },
199
- ]),
200
- remote: vi.fn(async () => {
201
- startupOpLog.push("git:remote");
202
- }),
203
- revparse: vi.fn(async (ref: string) => {
204
- startupOpLog.push(`git:revparse:${ref}`);
205
- return "abc123\n";
206
- }),
207
- checkout: vi.fn(async () => {
208
- startupOpLog.push("git:checkout");
209
- }),
210
- checkoutOrCreate: vi.fn(async () => {
211
- startupOpLog.push("git:checkoutOrCreate");
212
- }),
213
- };
214
- }
215
- return { startupOpLog, buildMockGitService, mockGetNpmRegistryClient };
216
- });
169
+ }
170
+ return "";
171
+ }),
172
+ push: vi.fn(async () => {
173
+ startupOpLog.push("git:push");
174
+ }),
175
+ getDefaultBranch: vi.fn(async () => "main"),
176
+ getRemotes: vi.fn(async () => [
177
+ { name: "origin", refs: { fetch: "https://example.test/repo.git" } },
178
+ ]),
179
+ remote: vi.fn(async () => {
180
+ startupOpLog.push("git:remote");
181
+ }),
182
+ revparse: vi.fn(async (ref: string) => {
183
+ startupOpLog.push(`git:revparse:${ref}`);
184
+ return "abc123\n";
185
+ }),
186
+ checkout: vi.fn(async () => {
187
+ startupOpLog.push("git:checkout");
188
+ }),
189
+ checkoutOrCreate: vi.fn(async () => {
190
+ startupOpLog.push("git:checkoutOrCreate");
191
+ }),
192
+ };
193
+ }
194
+ return { startupOpLog, buildMockGitService };
195
+ });
217
196
 
218
197
  vi.mock("@superblocksteam/vite-plugin-file-sync/git-service", () => ({
219
198
  createGitService: vi.fn((cwd: string) => {
@@ -305,16 +284,10 @@ vi.mock("./automatic-upgrades.js", () => ({
305
284
  // `getNpmRegistryClient()` stub so the call site doesn't `TypeError`
306
285
  // and silently swallow this mock.
307
286
  vi.mock("./home-npmrc.mjs", () => ({
308
- syncHomeNpmrc: vi.fn(async () => {
309
- // Longer delay than maybeWriteNpmrcForDir: if both run without await,
310
- // project pushes first and the order assertion fails.
311
- await new Promise((resolve) => setTimeout(resolve, 30));
312
- startupOpLog.push("home-npmrc:syncHomeNpmrc");
313
- return {
314
- outcome: "skipped-not-configured",
315
- path: "/tmp/.superblocks/npmrc",
316
- };
317
- }),
287
+ syncHomeNpmrc: vi.fn(async () => ({
288
+ outcome: "skipped-not-configured",
289
+ path: "/tmp/.superblocks/npmrc",
290
+ })),
318
291
  superblocksNpmrcPath: vi.fn(() => "/tmp/.superblocks/npmrc"),
319
292
  superblocksLogsPath: vi.fn((appDir: string) => `${appDir}/.superblocks/logs`),
320
293
  }));
@@ -410,7 +383,6 @@ function setupExecMock() {
410
383
  _opts: unknown,
411
384
  cb?: (err: null, result: { stdout: string }) => void,
412
385
  ) => {
413
- startupOpLog.push("installPackages:exec");
414
386
  if (typeof _opts === "function") {
415
387
  (_opts as (err: null, result: { stdout: string }) => void)(null, {
416
388
  stdout: "installed",
@@ -427,13 +399,6 @@ describe("dev startup: git reconciliation before DBFS download", () => {
427
399
 
428
400
  beforeEach(async () => {
429
401
  vi.clearAllMocks();
430
- mockGetNpmRegistryClient.mockImplementation(() => ({
431
- organizationId: "org-1",
432
- getConfig: vi.fn(async () => ({
433
- source: "not-configured",
434
- config: { configured: false },
435
- })),
436
- }));
437
402
  startupOpLog.length = 0;
438
403
  setupExecMock();
439
404
  mockCheckVersions.mockResolvedValue({
@@ -479,40 +444,4 @@ describe("dev startup: git reconciliation before DBFS download", () => {
479
444
  "[dev-startup] Post-download hash matches server",
480
445
  );
481
446
  });
482
-
483
- it("reconciles project .npmrc after home sync and before boot install", async () => {
484
- const { maybeWriteNpmrcForDir } =
485
- await import("@superblocksteam/vite-plugin-file-sync/npm-registry");
486
- const { syncHomeNpmrc } = await import("./home-npmrc.mjs");
487
- const { dev } = await import("./dev.mjs");
488
-
489
- await dev(buildDevOptions(testCwd) as any);
490
-
491
- const homeIdx = startupOpLog.indexOf("home-npmrc:syncHomeNpmrc");
492
- const projectIdx = startupOpLog.indexOf(
493
- "project-npmrc:maybeWriteNpmrcForDir",
494
- );
495
- const installIdx = startupOpLog.indexOf("installPackages:exec");
496
-
497
- expect(syncHomeNpmrc).toHaveBeenCalled();
498
- expect(maybeWriteNpmrcForDir).toHaveBeenCalled();
499
- expect(homeIdx).toBeGreaterThanOrEqual(0);
500
- expect(projectIdx).toBeGreaterThanOrEqual(0);
501
- expect(homeIdx).toBeLessThan(projectIdx);
502
- if (installIdx >= 0) {
503
- expect(projectIdx).toBeLessThan(installIdx);
504
- }
505
- });
506
-
507
- it("skips project .npmrc reconcile when the npm registry client is absent", async () => {
508
- mockGetNpmRegistryClient.mockReturnValue(undefined);
509
- const { maybeWriteNpmrcForDir } =
510
- await import("@superblocksteam/vite-plugin-file-sync/npm-registry");
511
- const { dev } = await import("./dev.mjs");
512
-
513
- await dev(buildDevOptions(testCwd) as any);
514
-
515
- expect(maybeWriteNpmrcForDir).not.toHaveBeenCalled();
516
- expect(startupOpLog).not.toContain("project-npmrc:maybeWriteNpmrcForDir");
517
- });
518
447
  });
@@ -1,7 +1,6 @@
1
1
  import * as child_process from "node:child_process";
2
2
  import * as nodeFs from "node:fs/promises";
3
3
  import type { Server as HttpServer } from "node:http";
4
- import os from "node:os";
5
4
  import path from "node:path";
6
5
  import * as readline from "node:readline";
7
6
  import { promisify } from "node:util";
@@ -25,7 +24,6 @@ import {
25
24
  isGitHubRemoteUrl,
26
25
  SUPERBLOCKS_LIVE_GIT_BRANCH,
27
26
  } from "@superblocksteam/shared";
28
- import { npmRegistryEmitter } from "@superblocksteam/telemetry";
29
27
  import { maskUnixSignals } from "@superblocksteam/util";
30
28
  import {
31
29
  AiService,
@@ -47,7 +45,6 @@ import {
47
45
  type NpmRegistryFetchResult,
48
46
  type ParseContext,
49
47
  NpmInstallBlocked,
50
- maybeWriteNpmrcForDir,
51
48
  shouldIgnoreInstallScripts,
52
49
  } from "@superblocksteam/vite-plugin-file-sync/npm-registry";
53
50
  import { OperationQueue } from "@superblocksteam/vite-plugin-file-sync/operation-queue";
@@ -100,7 +97,6 @@ import {
100
97
  syncHomeNpmrc,
101
98
  } from "./home-npmrc.mjs";
102
99
  import { normalizeWorkspaceProtocolForNpm } from "./normalize-workspace-protocol.js";
103
- import { readReapedChildCpuSeconds } from "./npm-install-cpu.mjs";
104
100
  import { parseNpmInstallSummary } from "./npm-install-summary.mjs";
105
101
  import { consumeNpmInstallTimingAttributes } from "./npm-install-timing.mjs";
106
102
  import {
@@ -646,11 +642,6 @@ export async function installPackages(
646
642
  env: buildInstallEnv(superblocksNpmrcPath(), logsDir),
647
643
  });
648
644
  installStart = Date.now();
649
- // Reaped-child cpu total before the install, so the delta across the
650
- // awaited spawn below covers the cpu the install burned. Compared against
651
- // the wall-clock duration it separates a compute-bound install from one
652
- // that spent its time waiting on the network or the disk.
653
- const childCpuSecondsBefore = await readReapedChildCpuSeconds();
654
645
 
655
646
  // Cheap `df` snapshot before the install (statfs only — no directory walk
656
647
  // on the happy path). On a 3Gi live-edit PVC this is the baseline that
@@ -669,7 +660,6 @@ export async function installPackages(
669
660
 
670
661
  const { stdout } = await runInstall();
671
662
  const installDurationMs = Date.now() - installStart;
672
- const childCpuSecondsAfter = await readReapedChildCpuSeconds();
673
663
  // npm's `--timing` breakdown lives in a file, so it has to be read back
674
664
  // once the install is done. Only npm writes one; reading under pnpm would
675
665
  // report a leftover npm file as this install's timings. The `catch` keeps
@@ -692,27 +682,11 @@ export async function installPackages(
692
682
  "Package installation completed successfully",
693
683
  attributes,
694
684
  );
695
- // Cpu the install burned, to be read against the wall-clock duration
696
- // beside it. Omitted rather than zeroed where procfs is unavailable, so a
697
- // reading we could not take never looks like an install that used no cpu.
698
- // The core count is what makes the ratio interpretable: 19 cpu-seconds
699
- // over 19 wall-seconds is saturated on one core and nearly idle on eight.
700
- const cpuAttributes: Record<string, number> =
701
- childCpuSecondsBefore !== null && childCpuSecondsAfter !== null
702
- ? {
703
- "superblocks.npm.install.cpu_count": os.availableParallelism(),
704
- "superblocks.npm.install.cpu_seconds": Math.max(
705
- 0,
706
- childCpuSecondsAfter - childCpuSecondsBefore,
707
- ),
708
- }
709
- : {};
710
685
  // Reuse the existing npm-install namespace and its duration unit. The
711
686
  // package counts are log-only sizing data from this separate install path.
712
687
  const commonAttributes = {
713
688
  "superblocks.npm.install.disk_recovered": false,
714
689
  "superblocks.npm.install.duration_seconds": installDurationMs / 1000,
715
- ...cpuAttributes,
716
690
  ...timingAttributes,
717
691
  };
718
692
  if (summary) {
@@ -2022,22 +1996,6 @@ export async function dev(options: {
2022
1996
  }
2023
1997
  }
2024
1998
 
2025
- // Reconcile the project-dir `.npmrc` on the live-edit PVC before
2026
- // the boot install. Home sync alone is not enough: npm prefers
2027
- // the project file, which can hold a stale JWT or a
2028
- // deleted-registry proxy URL across pod recycles.
2029
- if (npmRegistryClient) {
2030
- try {
2031
- await maybeWriteNpmrcForDir(cwd, npmRegistryClient);
2032
- } catch (error) {
2033
- logger.warn(
2034
- "[project-npmrc] boot reconcile failed unexpectedly; project .npmrc left untouched",
2035
- getErrorMeta(error),
2036
- );
2037
- npmRegistryEmitter.recordSyncProjectNpmrc("error");
2038
- }
2039
- }
2040
-
2041
1999
  let hasCliUpdated = false;
2042
2000
  let upgradePromises: Promise<void>[] = [];
2043
2001
  const forceUpgrade =
@@ -76,16 +76,6 @@ vi.mock("./npm-install-timing.mjs", () => ({
76
76
  consumeTimingMock(logsDir),
77
77
  }));
78
78
 
79
- // Install cpu time is read from procfs, which does not exist on macOS, so a
80
- // real read would make the emitted attributes differ between a developer
81
- // machine and CI. The reader has its own coverage in `npm-install-cpu.test.mts`;
82
- // here we only care that a reading reaches the success log line, and that no
83
- // reading leaves the attributes off it entirely.
84
- const readChildCpuMock = vi.fn<() => Promise<number | null>>(async () => null);
85
- vi.mock("./npm-install-cpu.mjs", () => ({
86
- readReapedChildCpuSeconds: () => readChildCpuMock(),
87
- }));
88
-
89
79
  const mockLogger = {
90
80
  info: vi.fn(),
91
81
  infoStructured: vi.fn(),
@@ -402,39 +392,6 @@ describe("installPackages success logging", () => {
402
392
  expect(mockLogger.info).toHaveBeenCalledWith("ok");
403
393
  });
404
394
 
405
- it("emits the cpu time the install burned alongside its wall-clock duration", async () => {
406
- // Two reads bracket the install, so the emitted figure is the difference.
407
- readChildCpuMock.mockResolvedValueOnce(12).mockResolvedValueOnce(30.5);
408
- const { installPackages } = await import("./dev.mjs");
409
-
410
- await installPackages("/tmp/app", mockLogger as never);
411
-
412
- expect(mockLogger.infoStructured).toHaveBeenCalledWith(
413
- "Package installation completed successfully",
414
- expect.objectContaining({
415
- "superblocks.npm.install.cpu_count": expect.any(Number),
416
- "superblocks.npm.install.cpu_seconds": 18.5,
417
- "superblocks.npm.install.duration_seconds": expect.any(Number),
418
- }),
419
- );
420
- });
421
-
422
- it("omits cpu attributes when only one of the two reads succeeds", async () => {
423
- // Half a measurement is not one: a difference taken against a missing
424
- // baseline would invent a number rather than report one.
425
- readChildCpuMock.mockResolvedValueOnce(12).mockResolvedValueOnce(null);
426
- const { installPackages } = await import("./dev.mjs");
427
-
428
- await installPackages("/tmp/app", mockLogger as never);
429
-
430
- expect(mockLogger.infoStructured).toHaveBeenCalledWith(
431
- "Package installation completed successfully",
432
- expect.not.objectContaining({
433
- "superblocks.npm.install.cpu_seconds": expect.anything(),
434
- }),
435
- );
436
- });
437
-
438
395
  it("marks parsed npm summaries and emits their counts", async () => {
439
396
  const stdout = JSON.stringify({
440
397
  added: 8,