@indigoai-us/hq-cli 5.77.8 → 5.77.9
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.
- package/CHANGELOG.md +19 -1
- package/dist/lib/plan-limit-nag.d.ts +45 -0
- package/dist/lib/plan-limit-nag.js +212 -0
- package/dist/main.js +4 -0
- package/dist/utils/vault-api.js +62 -1
- package/dist/utils/version-gate.d.ts +97 -1
- package/dist/utils/version-gate.js +211 -32
- package/package.json +1 -1
- package/src/commands/reindex.test.ts +1 -1
- package/src/lib/plan-limit-nag.test.ts +317 -0
- package/src/lib/plan-limit-nag.ts +264 -0
- package/src/main.ts +4 -0
- package/src/utils/vault-api.test.ts +139 -0
- package/src/utils/vault-api.ts +61 -1
- package/src/utils/version-gate.test.ts +415 -6
- package/src/utils/version-gate.ts +259 -33
|
@@ -28,6 +28,25 @@ async function loadModule() {
|
|
|
28
28
|
return await import("./version-gate.js");
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
+
/**
|
|
32
|
+
* `RunningInstall` fixtures. `resolveRunningInstall()` is the single
|
|
33
|
+
* package-root walk the gate performs, so tests inject its result rather than
|
|
34
|
+
* a manager and a prefix separately.
|
|
35
|
+
*/
|
|
36
|
+
function npmInstall(prefix: string | null) {
|
|
37
|
+
return { manager: "npm" as const, prefix, packageRoot: null };
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function pnpmInstall() {
|
|
41
|
+
// pnpm-managed installs never carry a prefix — see resolveRunningInstall().
|
|
42
|
+
return {
|
|
43
|
+
manager: "pnpm" as const,
|
|
44
|
+
prefix: null,
|
|
45
|
+
packageRoot:
|
|
46
|
+
"/Users/x/Library/pnpm/global/5/.pnpm/@indigoai-us+hq-cli@5.61.0/node_modules/@indigoai-us/hq-cli",
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
31
50
|
describe("shouldSkipGate", () => {
|
|
32
51
|
it("returns true for --version", async () => {
|
|
33
52
|
const { shouldSkipGate } = await loadModule();
|
|
@@ -311,7 +330,7 @@ describe("enforceVersionGate — hard-update path", () => {
|
|
|
311
330
|
updateCommand: "npm install -g @indigoai-us/hq-cli@latest",
|
|
312
331
|
},
|
|
313
332
|
{
|
|
314
|
-
|
|
333
|
+
resolveInstall: () => npmInstall(prefix),
|
|
315
334
|
runner,
|
|
316
335
|
},
|
|
317
336
|
),
|
|
@@ -356,7 +375,7 @@ describe("enforceVersionGate — hard-update path", () => {
|
|
|
356
375
|
},
|
|
357
376
|
{
|
|
358
377
|
performUpdateString,
|
|
359
|
-
|
|
378
|
+
resolveInstall: () => npmInstall(null),
|
|
360
379
|
},
|
|
361
380
|
),
|
|
362
381
|
).toThrow(/__process_exit__:0/);
|
|
@@ -392,7 +411,7 @@ describe("enforceVersionGate — hard-update path", () => {
|
|
|
392
411
|
updateRecommended: false,
|
|
393
412
|
updateCommand: "npm install -g @indigoai-us/hq-cli@latest",
|
|
394
413
|
},
|
|
395
|
-
{
|
|
414
|
+
{ resolveInstall: () => npmInstall(prefix), runner },
|
|
396
415
|
),
|
|
397
416
|
).toThrow(/__process_exit__:0/); // succeeds after the sudo retry
|
|
398
417
|
|
|
@@ -429,7 +448,7 @@ describe("enforceVersionGate — hard-update path", () => {
|
|
|
429
448
|
updateRecommended: false,
|
|
430
449
|
updateCommand: "npm install -g @indigoai-us/hq-cli@latest",
|
|
431
450
|
},
|
|
432
|
-
{
|
|
451
|
+
{ resolveInstall: () => npmInstall("/usr"), runner },
|
|
433
452
|
),
|
|
434
453
|
).toThrow(/__process_exit__:75/);
|
|
435
454
|
|
|
@@ -472,7 +491,7 @@ describe("enforceVersionGate — hard-update path", () => {
|
|
|
472
491
|
updateRecommended: false,
|
|
473
492
|
updateCommand: "npm install -g @indigoai-us/hq-cli@latest",
|
|
474
493
|
},
|
|
475
|
-
{
|
|
494
|
+
{ resolveInstall: () => npmInstall(prefix), runner, cleanStale },
|
|
476
495
|
),
|
|
477
496
|
).toThrow(/__process_exit__:0/); // recovers after the cleanup + retry
|
|
478
497
|
|
|
@@ -520,7 +539,7 @@ describe("enforceVersionGate — hard-update path", () => {
|
|
|
520
539
|
updateRecommended: false,
|
|
521
540
|
updateCommand: "npm install -g @indigoai-us/hq-cli@latest",
|
|
522
541
|
},
|
|
523
|
-
{
|
|
542
|
+
{ resolveInstall: () => npmInstall("/usr"), runner, cleanStale },
|
|
524
543
|
),
|
|
525
544
|
).toThrow(/__process_exit__:0/); // sudo retry succeeds
|
|
526
545
|
|
|
@@ -613,3 +632,393 @@ describe("cleanStalePartialInstall", () => {
|
|
|
613
632
|
expect(result).toEqual([`${scopeDir}/.hq-cli-abc123`]);
|
|
614
633
|
});
|
|
615
634
|
});
|
|
635
|
+
|
|
636
|
+
// Regression coverage for feedback_812a6727: a pnpm-managed global install kept
|
|
637
|
+
// reporting the old version after every "successful" self-update, because the
|
|
638
|
+
// gate derived an npm --prefix from the pnpm store and installed into a
|
|
639
|
+
// directory the pnpm PATH shim never reads.
|
|
640
|
+
describe("pnpm-managed global installs", () => {
|
|
641
|
+
const PNPM_STORE_DIR =
|
|
642
|
+
"/Users/x/Library/pnpm/global/5/.pnpm/@indigoai-us+hq-cli@5.61.0/node_modules/@indigoai-us/hq-cli";
|
|
643
|
+
const PNPM_LINK_DIR =
|
|
644
|
+
"/Users/x/Library/pnpm/global/5/node_modules/@indigoai-us/hq-cli";
|
|
645
|
+
|
|
646
|
+
it("recognises both the store and the symlinked pnpm global layouts", async () => {
|
|
647
|
+
const { __test__ } = await loadModule();
|
|
648
|
+
expect(__test__.isPnpmManagedPackageDir(PNPM_STORE_DIR)).toBe(true);
|
|
649
|
+
expect(__test__.isPnpmManagedPackageDir(PNPM_LINK_DIR)).toBe(true);
|
|
650
|
+
expect(
|
|
651
|
+
__test__.isPnpmManagedPackageDir(
|
|
652
|
+
"C:\\Users\\x\\AppData\\Local\\pnpm\\global\\5\\node_modules\\@indigoai-us\\hq-cli",
|
|
653
|
+
),
|
|
654
|
+
).toBe(true);
|
|
655
|
+
});
|
|
656
|
+
|
|
657
|
+
it("does not mistake an npm global layout for a pnpm one", async () => {
|
|
658
|
+
const { __test__ } = await loadModule();
|
|
659
|
+
expect(
|
|
660
|
+
__test__.isPnpmManagedPackageDir(
|
|
661
|
+
"/usr/local/lib/node_modules/@indigoai-us/hq-cli",
|
|
662
|
+
),
|
|
663
|
+
).toBe(false);
|
|
664
|
+
expect(
|
|
665
|
+
__test__.isPnpmManagedPackageDir(
|
|
666
|
+
"/Users/x/.nvm/versions/node/v22.3.0/lib/node_modules/@indigoai-us/hq-cli",
|
|
667
|
+
),
|
|
668
|
+
).toBe(false);
|
|
669
|
+
// A project that merely depends on pnpm-named packages is still npm-shaped.
|
|
670
|
+
expect(
|
|
671
|
+
__test__.isPnpmManagedPackageDir(
|
|
672
|
+
"/Users/x/code/pnpm-tools/node_modules/@indigoai-us/hq-cli",
|
|
673
|
+
),
|
|
674
|
+
).toBe(false);
|
|
675
|
+
});
|
|
676
|
+
|
|
677
|
+
it("demonstrates the old bug: a pnpm store path yields a plausible-looking npm prefix", async () => {
|
|
678
|
+
const { __test__ } = await loadModule();
|
|
679
|
+
// npmPrefixFromPackageDir is layout-blind — it happily hands back the pnpm
|
|
680
|
+
// store as if it were an npm prefix, which is exactly what made
|
|
681
|
+
// `npm install -g --prefix <store>` exit 0 while changing nothing the shim
|
|
682
|
+
// resolves. The manager check is what has to stop that.
|
|
683
|
+
expect(__test__.npmPrefixFromPackageDir(PNPM_STORE_DIR)).not.toBeNull();
|
|
684
|
+
expect(__test__.npmPrefixFromPackageDir(PNPM_LINK_DIR)).not.toBeNull();
|
|
685
|
+
expect(__test__.isPnpmManagedPackageDir(PNPM_STORE_DIR)).toBe(true);
|
|
686
|
+
expect(__test__.isPnpmManagedPackageDir(PNPM_LINK_DIR)).toBe(true);
|
|
687
|
+
});
|
|
688
|
+
|
|
689
|
+
it("builds the pnpm global install argv", async () => {
|
|
690
|
+
const { __test__ } = await loadModule();
|
|
691
|
+
expect(__test__.buildPnpmInstallArgv()).toEqual([
|
|
692
|
+
"add",
|
|
693
|
+
"-g",
|
|
694
|
+
"@indigoai-us/hq-cli@latest",
|
|
695
|
+
]);
|
|
696
|
+
});
|
|
697
|
+
|
|
698
|
+
it("updates with `pnpm add -g` and never npm-installs into the pnpm store", async () => {
|
|
699
|
+
vi.spyOn(console, "error").mockImplementation(() => {});
|
|
700
|
+
const exitSpy = vi
|
|
701
|
+
.spyOn(process, "exit")
|
|
702
|
+
.mockImplementation(((code?: number) => {
|
|
703
|
+
throw new Error(`__process_exit__:${code ?? 0}`);
|
|
704
|
+
}) as never);
|
|
705
|
+
const runner = vi.fn().mockReturnValue({ ok: true });
|
|
706
|
+
const performUpdateString = vi.fn().mockReturnValue({ ok: true });
|
|
707
|
+
const { __test__ } = await loadModule();
|
|
708
|
+
|
|
709
|
+
expect(() =>
|
|
710
|
+
__test__.enforceUpdateRequired(
|
|
711
|
+
{
|
|
712
|
+
clientId: "hq-cli",
|
|
713
|
+
currentVersion: "5.10.0",
|
|
714
|
+
minVersion: "5.20.0",
|
|
715
|
+
latestVersion: "5.24.0",
|
|
716
|
+
updateRequired: true,
|
|
717
|
+
updateRecommended: false,
|
|
718
|
+
updateCommand: "npm install -g @indigoai-us/hq-cli@latest",
|
|
719
|
+
},
|
|
720
|
+
{
|
|
721
|
+
resolveInstall: () => pnpmInstall(),
|
|
722
|
+
performUpdateString,
|
|
723
|
+
runner,
|
|
724
|
+
},
|
|
725
|
+
),
|
|
726
|
+
).toThrow(/__process_exit__:0/);
|
|
727
|
+
|
|
728
|
+
expect(exitSpy).toHaveBeenCalledWith(0);
|
|
729
|
+
expect(runner).toHaveBeenCalledWith("pnpm", [
|
|
730
|
+
"add",
|
|
731
|
+
"-g",
|
|
732
|
+
"@indigoai-us/hq-cli@latest",
|
|
733
|
+
]);
|
|
734
|
+
// No npm anywhere: not the prefixed form, not the server's command.
|
|
735
|
+
expect(runner).not.toHaveBeenCalledWith("npm", expect.anything());
|
|
736
|
+
expect(performUpdateString).not.toHaveBeenCalled();
|
|
737
|
+
});
|
|
738
|
+
|
|
739
|
+
it("exits 75 without a sudo retry when the pnpm update fails", async () => {
|
|
740
|
+
vi.spyOn(console, "error").mockImplementation(() => {});
|
|
741
|
+
const exitSpy = vi
|
|
742
|
+
.spyOn(process, "exit")
|
|
743
|
+
.mockImplementation(((code?: number) => {
|
|
744
|
+
throw new Error(`__process_exit__:${code ?? 0}`);
|
|
745
|
+
}) as never);
|
|
746
|
+
const runner = vi.fn().mockReturnValue({ ok: false, detail: "EACCES" });
|
|
747
|
+
const cleanStale = vi.fn().mockReturnValue([]);
|
|
748
|
+
const { __test__ } = await loadModule();
|
|
749
|
+
|
|
750
|
+
expect(() =>
|
|
751
|
+
__test__.enforceUpdateRequired(
|
|
752
|
+
{
|
|
753
|
+
clientId: "hq-cli",
|
|
754
|
+
currentVersion: "5.10.0",
|
|
755
|
+
minVersion: "5.20.0",
|
|
756
|
+
latestVersion: "5.24.0",
|
|
757
|
+
updateRequired: true,
|
|
758
|
+
updateRecommended: false,
|
|
759
|
+
updateCommand: "npm install -g @indigoai-us/hq-cli@latest",
|
|
760
|
+
},
|
|
761
|
+
{
|
|
762
|
+
resolveInstall: () => pnpmInstall(),
|
|
763
|
+
runner,
|
|
764
|
+
cleanStale,
|
|
765
|
+
},
|
|
766
|
+
),
|
|
767
|
+
).toThrow(/__process_exit__:75/);
|
|
768
|
+
|
|
769
|
+
expect(exitSpy).toHaveBeenCalledWith(75);
|
|
770
|
+
// `sudo -n pnpm add -g` would install into root's PNPM_HOME and report
|
|
771
|
+
// success while the user's shim stayed stale — the failure must surface.
|
|
772
|
+
expect(runner).not.toHaveBeenCalledWith("sudo", expect.anything());
|
|
773
|
+
expect(cleanStale).not.toHaveBeenCalled();
|
|
774
|
+
expect(runner.mock.calls.every((c) => c[0] === "pnpm")).toBe(true);
|
|
775
|
+
});
|
|
776
|
+
|
|
777
|
+
it("still uses npm when the running install is npm-managed", async () => {
|
|
778
|
+
vi.spyOn(console, "error").mockImplementation(() => {});
|
|
779
|
+
vi.spyOn(process, "exit").mockImplementation(((code?: number) => {
|
|
780
|
+
throw new Error(`__process_exit__:${code ?? 0}`);
|
|
781
|
+
}) as never);
|
|
782
|
+
const runner = vi.fn().mockReturnValue({ ok: true });
|
|
783
|
+
const { __test__ } = await loadModule();
|
|
784
|
+
const prefix = "/usr/local";
|
|
785
|
+
|
|
786
|
+
expect(() =>
|
|
787
|
+
__test__.enforceUpdateRequired(
|
|
788
|
+
{
|
|
789
|
+
clientId: "hq-cli",
|
|
790
|
+
currentVersion: "5.10.0",
|
|
791
|
+
minVersion: "5.20.0",
|
|
792
|
+
latestVersion: "5.24.0",
|
|
793
|
+
updateRequired: true,
|
|
794
|
+
updateRecommended: false,
|
|
795
|
+
updateCommand: "npm install -g @indigoai-us/hq-cli@latest",
|
|
796
|
+
},
|
|
797
|
+
{ resolveInstall: () => npmInstall(prefix), runner },
|
|
798
|
+
),
|
|
799
|
+
).toThrow(/__process_exit__:0/);
|
|
800
|
+
|
|
801
|
+
expect(runner).toHaveBeenCalledWith("npm", [
|
|
802
|
+
"install",
|
|
803
|
+
"-g",
|
|
804
|
+
"--prefix",
|
|
805
|
+
prefix,
|
|
806
|
+
"@indigoai-us/hq-cli@latest",
|
|
807
|
+
]);
|
|
808
|
+
expect(runner).not.toHaveBeenCalledWith("pnpm", expect.anything());
|
|
809
|
+
});
|
|
810
|
+
});
|
|
811
|
+
|
|
812
|
+
// Second round of regression coverage for feedback_812a6727. The first fix made
|
|
813
|
+
// only the HARD gate (updateRequired) pnpm-aware; everything below closes the
|
|
814
|
+
// paths that could still reproduce the reported stale-shim loop, or that the
|
|
815
|
+
// pnpm branch newly mis-handled.
|
|
816
|
+
describe("pnpm-managed installs — soft nudge path", () => {
|
|
817
|
+
const decision = {
|
|
818
|
+
clientId: "hq-cli",
|
|
819
|
+
currentVersion: "5.10.0",
|
|
820
|
+
minVersion: "5.0.0",
|
|
821
|
+
latestVersion: "5.24.0",
|
|
822
|
+
updateRequired: false,
|
|
823
|
+
updateRecommended: true,
|
|
824
|
+
updateCommand: "npm install -g @indigoai-us/hq-cli@latest",
|
|
825
|
+
};
|
|
826
|
+
|
|
827
|
+
it("never tells a pnpm-managed install to run an npm command", async () => {
|
|
828
|
+
// updateRecommended fires for EVERY version below latest, while
|
|
829
|
+
// updateRequired only fires below minVersion — so this is the path a real
|
|
830
|
+
// user hits first. Printing the server's npm-shaped command here installs a
|
|
831
|
+
// fresh copy under the npm global prefix while pnpm's PATH shim keeps
|
|
832
|
+
// resolving the old build: the reported symptom, on a released build.
|
|
833
|
+
const errSpy = vi.spyOn(console, "error").mockImplementation(() => {});
|
|
834
|
+
const { __test__ } = await loadModule();
|
|
835
|
+
|
|
836
|
+
__test__.nudgeUpdateRecommended(decision, pnpmInstall());
|
|
837
|
+
|
|
838
|
+
const printed = errSpy.mock.calls.map((c) => c.join(" ")).join("\n");
|
|
839
|
+
expect(printed).toContain("5.24.0");
|
|
840
|
+
expect(printed).toContain("pnpm add -g @indigoai-us/hq-cli@latest");
|
|
841
|
+
expect(printed).not.toContain("npm install");
|
|
842
|
+
});
|
|
843
|
+
|
|
844
|
+
it("still prints the server updateCommand for an npm-managed install", async () => {
|
|
845
|
+
const errSpy = vi.spyOn(console, "error").mockImplementation(() => {});
|
|
846
|
+
const { __test__ } = await loadModule();
|
|
847
|
+
|
|
848
|
+
__test__.nudgeUpdateRecommended(decision, npmInstall("/usr/local"));
|
|
849
|
+
|
|
850
|
+
const printed = errSpy.mock.calls.map((c) => c.join(" ")).join("\n");
|
|
851
|
+
expect(printed).toContain("npm install -g @indigoai-us/hq-cli@latest");
|
|
852
|
+
expect(printed).not.toContain("pnpm");
|
|
853
|
+
});
|
|
854
|
+
});
|
|
855
|
+
|
|
856
|
+
describe("isPnpmManagedPackageDir — global layouts only", () => {
|
|
857
|
+
it("rejects a LOCAL pnpm project dependency", async () => {
|
|
858
|
+
// `pnpm add -g` would mutate the user's GLOBAL install as a side effect of
|
|
859
|
+
// a non-global invocation, while the local copy actually running stayed
|
|
860
|
+
// stale — so the gate would re-fire (and re-install globally) forever.
|
|
861
|
+
const { __test__ } = await loadModule();
|
|
862
|
+
expect(
|
|
863
|
+
__test__.isPnpmManagedPackageDir(
|
|
864
|
+
"/Users/x/code/my-app/node_modules/.pnpm/@indigoai-us+hq-cli@5.61.0/node_modules/@indigoai-us/hq-cli",
|
|
865
|
+
),
|
|
866
|
+
).toBe(false);
|
|
867
|
+
expect(
|
|
868
|
+
__test__.isPnpmManagedPackageDir(
|
|
869
|
+
"/Users/x/code/my-app/node_modules/@indigoai-us/hq-cli",
|
|
870
|
+
),
|
|
871
|
+
).toBe(false);
|
|
872
|
+
});
|
|
873
|
+
|
|
874
|
+
it("rejects a `pnpm dlx` cache directory", async () => {
|
|
875
|
+
const { __test__ } = await loadModule();
|
|
876
|
+
expect(
|
|
877
|
+
__test__.isPnpmManagedPackageDir(
|
|
878
|
+
"/Users/x/Library/pnpm/store/v3/tmp/dlx-49281/node_modules/.pnpm/@indigoai-us+hq-cli@5.61.0/node_modules/@indigoai-us/hq-cli",
|
|
879
|
+
),
|
|
880
|
+
).toBe(false);
|
|
881
|
+
});
|
|
882
|
+
|
|
883
|
+
it("rejects a dlx cache even when it sits under PNPM_HOME", async () => {
|
|
884
|
+
vi.stubEnv("PNPM_HOME", "/Users/x/Library/pnpm");
|
|
885
|
+
const { __test__ } = await loadModule();
|
|
886
|
+
expect(
|
|
887
|
+
__test__.isPnpmManagedPackageDir(
|
|
888
|
+
"/Users/x/Library/pnpm/store/v3/tmp/dlx-49281/node_modules/@indigoai-us/hq-cli",
|
|
889
|
+
),
|
|
890
|
+
).toBe(false);
|
|
891
|
+
});
|
|
892
|
+
|
|
893
|
+
it("accepts a PNPM_HOME global root whose store dir is not numeric", async () => {
|
|
894
|
+
vi.stubEnv("PNPM_HOME", "/opt/pnpm-home");
|
|
895
|
+
const { __test__ } = await loadModule();
|
|
896
|
+
expect(
|
|
897
|
+
__test__.isPnpmManagedPackageDir(
|
|
898
|
+
"/opt/pnpm-home/global/next/node_modules/@indigoai-us/hq-cli",
|
|
899
|
+
),
|
|
900
|
+
).toBe(true);
|
|
901
|
+
});
|
|
902
|
+
});
|
|
903
|
+
|
|
904
|
+
describe("buildSpawnPlan — Windows .cmd shims", () => {
|
|
905
|
+
it("spawns through the shell on win32 (Node refuses bare .cmd since CVE-2024-27980)", async () => {
|
|
906
|
+
const { __test__ } = await loadModule();
|
|
907
|
+
const plan = __test__.buildSpawnPlan(
|
|
908
|
+
"pnpm",
|
|
909
|
+
["add", "-g", "@indigoai-us/hq-cli@latest"],
|
|
910
|
+
"win32",
|
|
911
|
+
);
|
|
912
|
+
expect(plan.shell).toBe(true);
|
|
913
|
+
expect(plan.cmd).toBe("pnpm");
|
|
914
|
+
expect(plan.args).toEqual(["add", "-g", "@indigoai-us/hq-cli@latest"]);
|
|
915
|
+
});
|
|
916
|
+
|
|
917
|
+
it("quotes a prefix containing spaces, because Node does not quote for shell:true", async () => {
|
|
918
|
+
const { __test__ } = await loadModule();
|
|
919
|
+
const plan = __test__.buildSpawnPlan(
|
|
920
|
+
"npm",
|
|
921
|
+
["install", "-g", "--prefix", "C:/Program Files/npm", "pkg@latest"],
|
|
922
|
+
"win32",
|
|
923
|
+
);
|
|
924
|
+
expect(plan.args).toEqual([
|
|
925
|
+
"install",
|
|
926
|
+
"-g",
|
|
927
|
+
"--prefix",
|
|
928
|
+
'"C:/Program Files/npm"',
|
|
929
|
+
"pkg@latest",
|
|
930
|
+
]);
|
|
931
|
+
});
|
|
932
|
+
|
|
933
|
+
it("does not use a shell on posix", async () => {
|
|
934
|
+
const { __test__ } = await loadModule();
|
|
935
|
+
const plan = __test__.buildSpawnPlan("pnpm", ["add", "-g", "x"], "darwin");
|
|
936
|
+
expect(plan).toEqual({ cmd: "pnpm", args: ["add", "-g", "x"], shell: false });
|
|
937
|
+
});
|
|
938
|
+
});
|
|
939
|
+
|
|
940
|
+
describe("pnpm-managed installs — pnpm not spawnable", () => {
|
|
941
|
+
it("exits 75 with an actionable message when pnpm is missing from PATH", async () => {
|
|
942
|
+
// launchd/cron and other minimal-PATH parents never source the profile that
|
|
943
|
+
// puts PNPM_HOME on PATH. spawnSync surfaces that as an ENOENT `error`, not
|
|
944
|
+
// a throw and not a non-zero status.
|
|
945
|
+
const errSpy = vi.spyOn(console, "error").mockImplementation(() => {});
|
|
946
|
+
const exitSpy = vi
|
|
947
|
+
.spyOn(process, "exit")
|
|
948
|
+
.mockImplementation(((code?: number) => {
|
|
949
|
+
throw new Error(`__process_exit__:${code ?? 0}`);
|
|
950
|
+
}) as never);
|
|
951
|
+
const runner = vi.fn().mockReturnValue({
|
|
952
|
+
ok: false,
|
|
953
|
+
code: "ENOENT",
|
|
954
|
+
detail: "spawnSync pnpm ENOENT",
|
|
955
|
+
});
|
|
956
|
+
const { __test__ } = await loadModule();
|
|
957
|
+
|
|
958
|
+
expect(() =>
|
|
959
|
+
__test__.enforceUpdateRequired(
|
|
960
|
+
{
|
|
961
|
+
clientId: "hq-cli",
|
|
962
|
+
currentVersion: "5.10.0",
|
|
963
|
+
minVersion: "5.20.0",
|
|
964
|
+
latestVersion: "5.24.0",
|
|
965
|
+
updateRequired: true,
|
|
966
|
+
updateRecommended: false,
|
|
967
|
+
updateCommand: "npm install -g @indigoai-us/hq-cli@latest",
|
|
968
|
+
},
|
|
969
|
+
{ resolveInstall: () => pnpmInstall(), runner },
|
|
970
|
+
),
|
|
971
|
+
).toThrow(/__process_exit__:75/);
|
|
972
|
+
|
|
973
|
+
expect(exitSpy).toHaveBeenCalledWith(75);
|
|
974
|
+
const printed = errSpy.mock.calls.map((c) => c.join(" ")).join("\n");
|
|
975
|
+
expect(printed).toContain("not found on PATH");
|
|
976
|
+
expect(printed).toContain("Try manually: pnpm add -g @indigoai-us/hq-cli@latest");
|
|
977
|
+
// The server's npm command may be shown, but only flagged as npm-only —
|
|
978
|
+
// never as the thing to run for this layout.
|
|
979
|
+
expect(printed).not.toMatch(/Try manually: npm/);
|
|
980
|
+
// Still no sudo retry: it would install into root's PNPM_HOME.
|
|
981
|
+
expect(runner).not.toHaveBeenCalledWith("sudo", expect.anything());
|
|
982
|
+
});
|
|
983
|
+
});
|
|
984
|
+
|
|
985
|
+
describe("resolveRunningInstall", () => {
|
|
986
|
+
it("is consulted exactly once per enforceUpdateRequired invocation", async () => {
|
|
987
|
+
// Manager and prefix used to be resolved by two independent walks of the
|
|
988
|
+
// directory tree, each reading and JSON-parsing a package.json per level,
|
|
989
|
+
// and the two could disagree if the filesystem moved between them.
|
|
990
|
+
vi.spyOn(console, "error").mockImplementation(() => {});
|
|
991
|
+
vi.spyOn(process, "exit").mockImplementation(((code?: number) => {
|
|
992
|
+
throw new Error(`__process_exit__:${code ?? 0}`);
|
|
993
|
+
}) as never);
|
|
994
|
+
const resolveInstall = vi.fn(() => npmInstall("/usr/local"));
|
|
995
|
+
const runner = vi.fn().mockReturnValue({ ok: true });
|
|
996
|
+
const { __test__ } = await loadModule();
|
|
997
|
+
|
|
998
|
+
expect(() =>
|
|
999
|
+
__test__.enforceUpdateRequired(
|
|
1000
|
+
{
|
|
1001
|
+
clientId: "hq-cli",
|
|
1002
|
+
currentVersion: "5.10.0",
|
|
1003
|
+
minVersion: "5.20.0",
|
|
1004
|
+
latestVersion: "5.24.0",
|
|
1005
|
+
updateRequired: true,
|
|
1006
|
+
updateRecommended: false,
|
|
1007
|
+
updateCommand: "npm install -g @indigoai-us/hq-cli@latest",
|
|
1008
|
+
},
|
|
1009
|
+
{ resolveInstall, runner },
|
|
1010
|
+
),
|
|
1011
|
+
).toThrow(/__process_exit__:0/);
|
|
1012
|
+
|
|
1013
|
+
expect(resolveInstall).toHaveBeenCalledTimes(1);
|
|
1014
|
+
});
|
|
1015
|
+
|
|
1016
|
+
it("reports manager and prefix from a single resolution", async () => {
|
|
1017
|
+
const { __test__ } = await loadModule();
|
|
1018
|
+
const install = __test__.resolveRunningInstall();
|
|
1019
|
+
expect(install.manager).toBe(__test__.resolveRunningManager());
|
|
1020
|
+
expect(install.prefix).toBe(__test__.resolveRunningPrefix());
|
|
1021
|
+
// A pnpm-managed install must never carry an npm prefix.
|
|
1022
|
+
if (install.manager === "pnpm") expect(install.prefix).toBeNull();
|
|
1023
|
+
});
|
|
1024
|
+
});
|