



























11import fsSync from "node:fs";
2+import os from "node:os";
3+import path from "node:path";
24import { describe, expect, it, vi } from "vitest";
35import { createNpmProjectInstallEnv } from "./npm-install-env.js";
467+const EXPECTED_MIN_FRESHNESS_ENV = {
8+NPM_CONFIG_BEFORE: "",
9+NPM_CONFIG_MIN_RELEASE_AGE: "",
10+"NPM_CONFIG_MIN-RELEASE-AGE": "",
11+npm_config_before: "",
12+"npm_config_min-release-age": "0",
13+npm_config_min_release_age: "",
14+};
15+516describe("npm project install env", () => {
617it("uses an absolute POSIX script shell for npm lifecycle scripts", () => {
718const platformSpy = vi.spyOn(process, "platform", "get").mockReturnValue("linux");
@@ -14,6 +25,7 @@ describe("npm project install env", () => {
1425PATH: "/tmp/openclaw-npm-global/bin",
1526}),
1627).toEqual({
28+ ...EXPECTED_MIN_FRESHNESS_ENV,
1729NPM_CONFIG_SCRIPT_SHELL: "/bin/sh",
1830PATH: "/tmp/openclaw-npm-global/bin",
1931npm_config_dry_run: "false",
@@ -40,6 +52,7 @@ describe("npm project install env", () => {
4052NPM_CONFIG_SCRIPT_SHELL: "/custom/sh",
4153}),
4254).toEqual({
55+ ...EXPECTED_MIN_FRESHNESS_ENV,
4356NPM_CONFIG_SCRIPT_SHELL: "/custom/sh",
4457npm_config_dry_run: "false",
4558npm_config_fetch_retries: "5",
@@ -56,6 +69,7 @@ describe("npm project install env", () => {
5669npm_config_script_shell: "/custom/lower-sh",
5770}),
5871).toEqual({
72+ ...EXPECTED_MIN_FRESHNESS_ENV,
5973npm_config_dry_run: "false",
6074npm_config_fetch_retries: "5",
6175npm_config_fetch_retry_maxtimeout: "120000",
@@ -71,4 +85,55 @@ describe("npm project install env", () => {
7185platformSpy.mockRestore();
7286}
7387});
88+89+it("bypasses npm release-age filters for OpenClaw-managed installs", () => {
90+const env = createNpmProjectInstallEnv({
91+NPM_CONFIG_BEFORE: "2026-01-01T00:00:00.000Z",
92+NPM_CONFIG_MIN_RELEASE_AGE: "7",
93+"npm_config_min-release-age": "7",
94+npm_config_before: "2026-01-01T00:00:00.000Z",
95+npm_config_min_release_age: "7",
96+});
97+98+expect(env.NPM_CONFIG_BEFORE).toBe("");
99+expect(env.npm_config_before).toBe("");
100+expect(env.NPM_CONFIG_MIN_RELEASE_AGE).toBe("");
101+expect(env["npm_config_min-release-age"]).toBe("0");
102+expect(env.npm_config_min_release_age).toBe("");
103+});
104+105+it("does not leak parent npm freshness env into explicit child envs", () => {
106+const previousBefore = process.env.NPM_CONFIG_BEFORE;
107+process.env.NPM_CONFIG_BEFORE = "2026-01-01T00:00:00.000Z";
108+try {
109+const env = createNpmProjectInstallEnv({});
110+111+expect(env.NPM_CONFIG_BEFORE).toBe("");
112+expect(env.npm_config_before).toBe("");
113+expect(env["npm_config_min-release-age"]).toBe("0");
114+} finally {
115+if (previousBefore == null) {
116+delete process.env.NPM_CONFIG_BEFORE;
117+} else {
118+process.env.NPM_CONFIG_BEFORE = previousBefore;
119+}
120+}
121+});
122+123+it("uses a current before override for explicit npm before policy", () => {
124+const dir = fsSync.mkdtempSync(path.join(os.tmpdir(), "openclaw-npmrc-"));
125+try {
126+const npmrc = path.join(dir, "npmrc");
127+fsSync.writeFileSync(npmrc, "before=2026-01-01T00:00:00.000Z\n", "utf-8");
128+const env = createNpmProjectInstallEnv({
129+NPM_CONFIG_USERCONFIG: npmrc,
130+});
131+132+expect(env["npm_config_min-release-age"]).toBe("");
133+expect(env.npm_config_before).toMatch(/^\d{4}-\d{2}-\d{2}T/);
134+expect(env.npm_config_before).not.toBe("2026-01-01T00:00:00.000Z");
135+} finally {
136+fsSync.rmSync(dir, { recursive: true, force: true });
137+}
138+});
74139});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。