@app-vitals/agent-lib 1.120.0 → 1.121.0
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/child-env.ts +12 -9
- package/child-env.unit.test.ts +12 -9
- package/package.json +1 -1
package/child-env.ts
CHANGED
|
@@ -74,7 +74,7 @@ const AGENT_KEY = "SHIPWRIGHT_AGENT_API_KEY";
|
|
|
74
74
|
|
|
75
75
|
let warnedMissingToolsKey = false;
|
|
76
76
|
|
|
77
|
-
/** Test hook: re-arm the once-per-process
|
|
77
|
+
/** Test hook: re-arm the once-per-process missing-key error. */
|
|
78
78
|
export function resetChildEnvWarning(): void {
|
|
79
79
|
warnedMissingToolsKey = false;
|
|
80
80
|
}
|
|
@@ -84,9 +84,9 @@ export function resetChildEnvWarning(): void {
|
|
|
84
84
|
* SHIPWRIGHT_AGENT_API_KEY, then layer `extra` last so a per-run override
|
|
85
85
|
* still wins.
|
|
86
86
|
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
87
|
+
* Fails closed: with no tools token the child gets no SHIPWRIGHT_AGENT_API_KEY
|
|
88
|
+
* at all (the runtime token never reaches the model's process) and one error is
|
|
89
|
+
* logged per process.
|
|
90
90
|
*/
|
|
91
91
|
export function buildChildEnv(
|
|
92
92
|
env: Record<string, string | undefined>,
|
|
@@ -98,11 +98,14 @@ export function buildChildEnv(
|
|
|
98
98
|
delete child[TOOLS_KEY];
|
|
99
99
|
if (toolsKey) {
|
|
100
100
|
child[AGENT_KEY] = toolsKey;
|
|
101
|
-
} else
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
101
|
+
} else {
|
|
102
|
+
delete child[AGENT_KEY];
|
|
103
|
+
if (!warnedMissingToolsKey) {
|
|
104
|
+
warnedMissingToolsKey = true;
|
|
105
|
+
console.error(
|
|
106
|
+
`[child-env] ${TOOLS_KEY} is not set; the child gets no ${AGENT_KEY}`,
|
|
107
|
+
);
|
|
108
|
+
}
|
|
106
109
|
}
|
|
107
110
|
return { ...child, ...extra };
|
|
108
111
|
}
|
package/child-env.unit.test.ts
CHANGED
|
@@ -13,6 +13,8 @@ describe("buildChildEnv", () => {
|
|
|
13
13
|
const env: Record<string, string> = { PATH: "/bin", MY_OPERATOR_VAR: "x" };
|
|
14
14
|
for (const k of RUNTIME_ONLY_ENV_VARS) env[k] = "secret";
|
|
15
15
|
for (const k of CHILD_ALLOWED_SECRET_ENV_VARS) env[k] = "ok";
|
|
16
|
+
// The agent key only reaches the child via the tools key (no fallback).
|
|
17
|
+
env.SHIPWRIGHT_AGENT_TOOLS_API_KEY = "ok";
|
|
16
18
|
const child = buildChildEnv(env);
|
|
17
19
|
for (const k of RUNTIME_ONLY_ENV_VARS) expect(k in child).toBe(false);
|
|
18
20
|
for (const k of CHILD_ALLOWED_SECRET_ENV_VARS) expect(child[k]).toBe("ok");
|
|
@@ -89,12 +91,12 @@ describe("secret classification", () => {
|
|
|
89
91
|
});
|
|
90
92
|
|
|
91
93
|
describe("buildChildEnv tools-token mapping", () => {
|
|
92
|
-
let
|
|
94
|
+
let errorLog: ReturnType<typeof spyOn>;
|
|
93
95
|
beforeEach(() => {
|
|
94
96
|
resetChildEnvWarning();
|
|
95
|
-
|
|
97
|
+
errorLog = spyOn(console, "error").mockImplementation(() => {});
|
|
96
98
|
});
|
|
97
|
-
afterEach(() =>
|
|
99
|
+
afterEach(() => errorLog.mockRestore());
|
|
98
100
|
|
|
99
101
|
test("MAPPED_ENV_VARS is the tools key and is not also pass-through", () => {
|
|
100
102
|
expect([...MAPPED_ENV_VARS]).toEqual(["SHIPWRIGHT_AGENT_TOOLS_API_KEY"]);
|
|
@@ -114,14 +116,15 @@ describe("buildChildEnv tools-token mapping", () => {
|
|
|
114
116
|
expect("SHIPWRIGHT_AGENT_TOOLS_API_KEY" in child).toBe(false);
|
|
115
117
|
expect(env.SHIPWRIGHT_AGENT_API_KEY).toBe("pod-key");
|
|
116
118
|
expect(env.SHIPWRIGHT_AGENT_TOOLS_API_KEY).toBe("tools-key");
|
|
117
|
-
expect(
|
|
119
|
+
expect(errorLog).not.toHaveBeenCalled();
|
|
118
120
|
});
|
|
119
121
|
|
|
120
|
-
test("without the tools key, the child
|
|
122
|
+
test("without the tools key, the child gets no agent key and one error is logged per process", () => {
|
|
121
123
|
const env = { SHIPWRIGHT_AGENT_API_KEY: "pod-key" };
|
|
122
|
-
expect(buildChildEnv(env)
|
|
123
|
-
expect(buildChildEnv(env)
|
|
124
|
-
expect(
|
|
124
|
+
expect("SHIPWRIGHT_AGENT_API_KEY" in buildChildEnv(env)).toBe(false);
|
|
125
|
+
expect("SHIPWRIGHT_AGENT_API_KEY" in buildChildEnv(env)).toBe(false);
|
|
126
|
+
expect(env.SHIPWRIGHT_AGENT_API_KEY).toBe("pod-key");
|
|
127
|
+
expect(errorLog).toHaveBeenCalledTimes(1);
|
|
125
128
|
});
|
|
126
129
|
|
|
127
130
|
test("an empty tools key counts as absent", () => {
|
|
@@ -129,7 +132,7 @@ describe("buildChildEnv tools-token mapping", () => {
|
|
|
129
132
|
SHIPWRIGHT_AGENT_API_KEY: "pod-key",
|
|
130
133
|
SHIPWRIGHT_AGENT_TOOLS_API_KEY: "",
|
|
131
134
|
});
|
|
132
|
-
expect(child
|
|
135
|
+
expect("SHIPWRIGHT_AGENT_API_KEY" in child).toBe(false);
|
|
133
136
|
expect("SHIPWRIGHT_AGENT_TOOLS_API_KEY" in child).toBe(false);
|
|
134
137
|
});
|
|
135
138
|
});
|