Skip to content

Commit 465feeb

Browse files
authored
test(config): prove inherited env refs are ignored
1 parent 79996ef commit 465feeb

1 file changed

Lines changed: 10 additions & 12 deletions

File tree

‎src/config/env-preserve.test.ts‎

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -834,17 +834,15 @@ describe("restoreEnvVarRefs", () => {
834834
});
835835
});
836836

837-
it("treats prototype-named keys as new caller keys, not matches in parsed", () => {
838-
// When a config key collides with an Object.prototype property name,
839-
// Object.hasOwn ensures we only match own properties of `parsed`,
840-
// not inherited ones.
841-
const incoming = { toString: "my-override", apiKey: "sk-ant-api03-real-key" };
842-
// parsed has own "apiKey" but NOT a "toString" own property:
843-
const parsed: Record<string, unknown> = { apiKey: "${ANTHROPIC_API_KEY}" };
844-
845-
const result = restoreEnvVarRefs(incoming, parsed, env);
846-
// "toString" is a new key not in parsed → keep as-is.
847-
// "apiKey" matches parsed own property → should restore the env var ref.
848-
expect(result).toEqual({ toString: "my-override", apiKey: "${ANTHROPIC_API_KEY}" });
837+
it("does not restore env refs from inherited parsed properties", () => {
838+
// isPlainObject accepts custom prototypes, but only own properties represent authored config.
839+
const parsed = Object.create({
840+
toString: "${TEST_VALUE}",
841+
}) as Record<string, unknown>;
842+
const testEnv = { TEST_VALUE: "resolved-value" } as unknown as NodeJS.ProcessEnv;
843+
844+
expect(restoreEnvVarRefs({ toString: "resolved-value" }, parsed, testEnv)).toEqual({
845+
toString: "resolved-value",
846+
});
849847
});
850848
});

0 commit comments

Comments
 (0)