pi-mono/packages/durable/test/harness-json.test.ts
Armin Ronacher 89c921d8b5 fix: harden handling of untrusted URLs, terminal text, and streamed data
- ai: OAuth logins only accept http(s) URLs from servers (shared
  trustedHttpUrl, now also checked by Radius); pi-messages rejects
  contentIndex values that are not the next or an existing block; the
  CLI auth file is written with mode 0600
- ai: OpenCode DeepSeek V4.1 Flash (renamed from V4 Flash upstream) no
  longer sends prompt_cache_retention
- tui: setTitle() replaces control characters; export
  replaceControlCharacters()
- coding-agent: the login dialog only opens web URLs and never prints
  control characters from sign-in, device-code, or info URLs
- durable: partial commits no longer merge a new __proto__ member into
  Object.prototype
2026-10-26 20:46:31 +01:00

23 lines
942 B
TypeScript

import { type JsonValue, track } from "@earendil-works/chord/delta";
import { describe, expect, it } from "vitest";
import { assignJson } from "../src/harness/json.ts";
type Doc = { message?: JsonValue };
function assign(tracker: ReturnType<typeof track<Doc>>, value: JsonValue): void {
const change = tracker.beginChange();
assignJson(change.state as Doc, "message", value);
tracker.adopt(change.prepare());
}
describe("assignJson", () => {
it("does not merge a new __proto__ member into Object.prototype", () => {
const tracker = track<Doc>({});
assign(tracker, { args: JSON.parse('{"path":"x"}') });
assign(tracker, { args: JSON.parse('{"path":"xy","__proto__":{"polluted":true}}') });
expect(({} as Record<string, unknown>).polluted).toBeUndefined();
const args = (tracker.value.message as { args: object }).args;
expect(Object.getOwnPropertyDescriptor(args, "__proto__")?.value).toEqual({ polluted: true });
});
});