@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 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 fallback warning. */
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
- * Phase A fallback: with no tools token the child keeps the old key and one
88
- * warning is logged per process, so a runtime deployed before admin's backfill
89
- * keeps working.
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 if (!warnedMissingToolsKey) {
102
- warnedMissingToolsKey = true;
103
- console.warn(
104
- `[child-env] ${TOOLS_KEY} is not set; the child keeps ${AGENT_KEY} (fallback)`,
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
  }
@@ -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 warn: ReturnType<typeof spyOn>;
94
+ let errorLog: ReturnType<typeof spyOn>;
93
95
  beforeEach(() => {
94
96
  resetChildEnvWarning();
95
- warn = spyOn(console, "warn").mockImplementation(() => {});
97
+ errorLog = spyOn(console, "error").mockImplementation(() => {});
96
98
  });
97
- afterEach(() => warn.mockRestore());
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(warn).not.toHaveBeenCalled();
119
+ expect(errorLog).not.toHaveBeenCalled();
118
120
  });
119
121
 
120
- test("without the tools key, the child keeps the old key and warns once per process", () => {
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).SHIPWRIGHT_AGENT_API_KEY).toBe("pod-key");
123
- expect(buildChildEnv(env).SHIPWRIGHT_AGENT_API_KEY).toBe("pod-key");
124
- expect(warn).toHaveBeenCalledTimes(1);
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.SHIPWRIGHT_AGENT_API_KEY).toBe("pod-key");
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
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@app-vitals/agent-lib",
3
- "version": "1.120.0",
3
+ "version": "1.121.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/app-vitals/agent.git",