Files
Triple-C/app/src/lib/claudeInput.test.ts
T
shadowdaoandClaude Opus 5 436b6dd470 Send a lone CR through the newline transform, and say what pinned is
`toClaudePayload` matched `/\r?\n/`, so a bare CR that is not part of a
CRLF went through verbatim — and a bare CR *submits* in a Claude prompt
and *runs* the line in a shell, which is the terminator the function's
own contract says it never appends. A `<textarea>` cannot produce one,
but `load_in` returns whatever a hand-edited or externally written notes
file holds, so the guarantee has to cover that rather than only what the
editor can type.

`Note.pinned` is persisted and sorted on, but nothing in the app sets
it: there is no pin control and no indicator. The spec stated the
ordering rule as though pinning existed and §8 did not list it, so the
spec is amended to say `pinned` is reserved and inert in v1, and pinning
is added to the out-of-scope list. No UI is added — a user-facing
affordance does not belong in a fix wave.

Also renamed NotesPanel.test.tsx's "deletes the selected note and falls
back to another": `useNotes` is mocked in that file and the mocked list
never changes, so the fallback was never exercised. A name that claims
coverage which is absent is worse than an absent test, because it makes
the gap invisible. The real assertion now lives against the real hook in
NotesPanel.shared.test.tsx.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HjL1E2JFNctUqCYotUwqqb
2026-09-01 13:47:01 -07:00

45 lines
1.9 KiB
TypeScript

import { describe, it, expect } from "vitest";
import { CLAUDE_SOFT_NEWLINE, toClaudePayload } from "./claudeInput";
describe("toClaudePayload", () => {
it("is ESC+CR, the sequence Claude Code's own /terminal-setup installs", () => {
expect(CLAUDE_SOFT_NEWLINE).toBe("\x1b\r");
});
it("replaces every newline so the note arrives as one prompt", () => {
// Typed raw, each \n submits — the note would arrive as three truncated
// messages instead of one.
expect(toClaudePayload("one\ntwo\nthree")).toBe("one\x1b\rtwo\x1b\rthree");
});
it("normalises CRLF, which is what a paste from Windows carries", () => {
expect(toClaudePayload("one\r\ntwo")).toBe("one\x1b\rtwo");
});
it("normalises a lone CR, which would otherwise submit", () => {
// A bare \r is a carriage return: it submits in a Claude prompt and runs
// the line in a shell — the terminator this function promises not to
// append. A textarea cannot make one, but a notes file that was
// hand-edited or written by something else can, and `load_in` hands it
// straight back.
expect(toClaudePayload("one\rtwo")).toBe("one\x1b\rtwo");
expect(toClaudePayload("one\rtwo\r\nthree\nfour")).toBe(
"one\x1b\rtwo\x1b\rthree\x1b\rfour",
);
expect(toClaudePayload("text\r").endsWith("\r")).toBe(true);
// …but only as the tail of the soft-newline sequence, never bare.
expect(toClaudePayload("text\r")).toBe("text\x1b\r");
});
it("leaves single-line text untouched", () => {
expect(toClaudePayload("just one line")).toBe("just one line");
});
it("never appends a terminator", () => {
// The note lands in the prompt unsubmitted; the user presses Enter. An
// unsent prompt is recoverable, a sent one is not.
expect(toClaudePayload("text").endsWith("\r")).toBe(false);
expect(toClaudePayload("text\n")).toBe("text\x1b\r");
});
});