Merge branch 'main' into web-routes
Resolve the L6 routes against the newer C2/C13/L5/R10 shell: keep both sides (single client imports, the run-alert watch inside the reconnect path, the boot route + popstate wiring alongside loadNotifyAsked, main's L5 row and L6 done).
This commit is contained in:
@@ -7,10 +7,30 @@ import assert from "node:assert/strict";
|
||||
import {
|
||||
BACKGROUND_TASKS_TITLE,
|
||||
BACKGROUND_TASK_VISIBLE_ROWS,
|
||||
CHAT_ACTIONS_LABEL,
|
||||
CHAT_COMMANDS,
|
||||
CHAT_COMMAND_DISMISS_LABEL,
|
||||
CHAT_COMMAND_FAILED_LABEL,
|
||||
CHAT_COMMAND_GLYPH,
|
||||
CHAT_COMMAND_LABEL,
|
||||
CHAT_CREATE_BACK_LABEL,
|
||||
CHAT_CREATE_CANCEL,
|
||||
CHAT_CREATE_CONFIRM,
|
||||
CHAT_CREATE_LOADING,
|
||||
CHAT_CREATE_MODEL_NOTE,
|
||||
CHAT_CREATE_PROMPT,
|
||||
CHAT_CREATE_TITLE,
|
||||
CHAT_FOLLOW_THRESHOLD_PX,
|
||||
CHAT_HIDE_ACTION,
|
||||
CHAT_QUEUED_NOTICE,
|
||||
CHAT_REMOVED_MESSAGE,
|
||||
CHAT_RENAME_ACTION,
|
||||
CHAT_RENAME_DISMISS,
|
||||
CHAT_RENAME_FIELD_LABEL,
|
||||
CHAT_RENAME_HELPER,
|
||||
CHAT_RENAME_SAVE,
|
||||
CHAT_RENAME_TITLE,
|
||||
CHAT_UNDO_ACTION,
|
||||
COMPOSER_SEND,
|
||||
COMPOSER_STOP,
|
||||
ChatTurn,
|
||||
@@ -48,7 +68,9 @@ import {
|
||||
TURN_PHASE_TOOL,
|
||||
TURN_PHASE_WAITING,
|
||||
TURN_THINKING_WINDOW_MILLIS,
|
||||
appendChatNotice,
|
||||
applyChatEvent,
|
||||
applyChatOverrides,
|
||||
applyChatPermission,
|
||||
approvalCard,
|
||||
approvalResources,
|
||||
@@ -56,18 +78,25 @@ import {
|
||||
attachmentDisplayName,
|
||||
attachmentError,
|
||||
attachmentFiles,
|
||||
HOME_DIRECTORY,
|
||||
HOME_LABEL,
|
||||
backgroundTasksRunningLabel,
|
||||
chatBottomDistancePx,
|
||||
chatCommandEffect,
|
||||
chatCommandForEnter,
|
||||
chatCommandHelp,
|
||||
chatCommandSuggestions,
|
||||
chatCreateFailed,
|
||||
chatCreateSucceeded,
|
||||
chatFirstScroll,
|
||||
chatFollowsAt,
|
||||
chatHeaderMeta,
|
||||
chatNoMatchMessage,
|
||||
chatNoticeLabel,
|
||||
chatOpensAtNewest,
|
||||
chatSeenWatermark,
|
||||
chatShowJumpToLatest,
|
||||
chatStartInLabel,
|
||||
chatStreamState,
|
||||
closeChatConfirmation,
|
||||
composerAction,
|
||||
@@ -75,28 +104,47 @@ import {
|
||||
composerSendEnabled,
|
||||
composerSubmit,
|
||||
decisionLabel,
|
||||
decodeChatOverrides,
|
||||
decodeChatSeen,
|
||||
defaultDirectoryChoice,
|
||||
deltaPartId,
|
||||
directoryChoices,
|
||||
directoryLabel,
|
||||
dismissChatNotice,
|
||||
emptyChatOverrides,
|
||||
emptyChatSeen,
|
||||
encodeChatOverrides,
|
||||
encodeChatSeen,
|
||||
filterSessions,
|
||||
formatToolDuration,
|
||||
groupSessionsByDirectory,
|
||||
hideChatOverride,
|
||||
historyResync,
|
||||
isChatSessionUnseen,
|
||||
lineDiff,
|
||||
makeChatNotice,
|
||||
markChatUnseen,
|
||||
mergeHistoryPage,
|
||||
mergeShellFrame,
|
||||
mergeToolPart,
|
||||
newChatCreateState,
|
||||
newChatThread,
|
||||
parseChatInput,
|
||||
partRendering,
|
||||
permissionRiskText,
|
||||
prettyToolInput,
|
||||
queuedAfterFrame,
|
||||
readChatSeen,
|
||||
reasoningLabel,
|
||||
renameChatOverride,
|
||||
restoreChatOverride,
|
||||
resumedThread,
|
||||
runningAfterFrame,
|
||||
runningBackgroundShells,
|
||||
runningToolElapsedMillis,
|
||||
runningToolStamps,
|
||||
seedChatSeen,
|
||||
selectChatDirectory,
|
||||
sessionActivity,
|
||||
sessionActivityBadge,
|
||||
sessionChipLabel,
|
||||
@@ -109,6 +157,7 @@ import {
|
||||
shellCommandSummary,
|
||||
shellOutputState,
|
||||
shellsLoaded,
|
||||
takeChatNoticeOffer,
|
||||
threadElapsedMillis,
|
||||
threadPhase,
|
||||
threadRunningTools,
|
||||
@@ -833,6 +882,103 @@ test("a command notice carries one terminal glyph for both states", () => {
|
||||
assert.equal(CHAT_COMMAND_GLYPH, ">_");
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Local command notices (C12) — ChatStore.kt notice/dismissNotice/takeNoticeOffer
|
||||
// and ChatCommandUi.kt's labels
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
test("chatNoticeLabel names a command and its failure", () => {
|
||||
assert.equal(CHAT_COMMAND_LABEL, "Command");
|
||||
assert.equal(CHAT_COMMAND_FAILED_LABEL, "Command failed");
|
||||
assert.equal(chatNoticeLabel(false), "Command");
|
||||
assert.equal(chatNoticeLabel(true), "Command failed");
|
||||
// Anything that is not the literal failed flag keeps the ordinary label.
|
||||
assert.equal(chatNoticeLabel(undefined), "Command");
|
||||
assert.equal(chatNoticeLabel("failed"), "Command");
|
||||
});
|
||||
|
||||
test("the offerless notice's dismiss control has an accessible name", () => {
|
||||
assert.equal(CHAT_COMMAND_DISMISS_LABEL, "Dismiss command notice");
|
||||
});
|
||||
|
||||
test("makeChatNotice keeps the id, text, failure flag and offer", () => {
|
||||
assert.deepEqual(makeChatNotice("notice-1", "No turn is running in this chat."), {
|
||||
id: "notice-1",
|
||||
text: "No turn is running in this chat.",
|
||||
failed: false,
|
||||
offer: null,
|
||||
});
|
||||
assert.deepEqual(
|
||||
makeChatNotice("notice-2", "Started a new session.", { failed: true, offer: "/nope" }),
|
||||
{ id: "notice-2", text: "Started a new session.", failed: true, offer: "/nope" },
|
||||
);
|
||||
});
|
||||
|
||||
test("appendChatNotice appends one notice and preserves order", () => {
|
||||
const first = makeChatNotice("notice-1", "Command one");
|
||||
const second = makeChatNotice("notice-2", "Command two", { failed: true });
|
||||
const afterFirst = appendChatNotice([], first);
|
||||
const afterSecond = appendChatNotice(afterFirst, second);
|
||||
assert.deepEqual(afterSecond, [first, second]);
|
||||
// The previous list is never mutated.
|
||||
assert.deepEqual(afterFirst, [first]);
|
||||
assert.deepEqual(appendChatNotice(undefined, first), [first]);
|
||||
});
|
||||
|
||||
test("dismissChatNotice removes exactly the named notice", () => {
|
||||
const first = makeChatNotice("notice-1", "Command one");
|
||||
const second = makeChatNotice("notice-2", "Command two", { failed: true });
|
||||
const third = makeChatNotice("notice-3", "Command three");
|
||||
assert.deepEqual(dismissChatNotice([first, second, third], "notice-2"), [first, third]);
|
||||
// An unknown id leaves the list as it was.
|
||||
assert.deepEqual(dismissChatNotice([first, third], "notice-9"), [first, third]);
|
||||
assert.deepEqual(dismissChatNotice(undefined, "notice-1"), []);
|
||||
});
|
||||
|
||||
test("takeChatNoticeOffer removes the notice and returns its draft", () => {
|
||||
const offerless = makeChatNotice("notice-1", "Command one");
|
||||
const offered = makeChatNotice("notice-2", "Not a command.", { failed: true, offer: "/nope" });
|
||||
const taken = takeChatNoticeOffer([offerless, offered], "notice-2");
|
||||
assert.equal(taken.offer, "/nope");
|
||||
assert.deepEqual(taken.notices, [offerless]);
|
||||
});
|
||||
|
||||
test("takeChatNoticeOffer returns null and leaves the list for a stale or offerless notice", () => {
|
||||
const offerless = makeChatNotice("notice-1", "Command one");
|
||||
const offered = makeChatNotice("notice-2", "Not a command.", { failed: true, offer: "/nope" });
|
||||
for (const id of ["notice-1", "notice-9"]) {
|
||||
const taken = takeChatNoticeOffer([offerless, offered], id);
|
||||
assert.equal(taken.offer, null);
|
||||
assert.deepEqual(taken.notices, [offerless, offered]);
|
||||
}
|
||||
// A second take of an already-taken id is stale and sends nothing.
|
||||
const firstTake = takeChatNoticeOffer([offered], "notice-2");
|
||||
const secondTake = takeChatNoticeOffer(firstTake.notices, "notice-2");
|
||||
assert.equal(secondTake.offer, null);
|
||||
assert.deepEqual(secondTake.notices, []);
|
||||
});
|
||||
|
||||
test("notice lists are scoped per conversation and never share state", () => {
|
||||
// Two conversations' notice lists are independent arrays: appending or
|
||||
// dismissing in one cannot touch the other (the app keeps one per thread).
|
||||
const operator = [];
|
||||
const throwaway = [];
|
||||
const operatorNotice = makeChatNotice("notice-1", "Operator command");
|
||||
const throwawayNotice = makeChatNotice("notice-2", "Throwaway command", { failed: true });
|
||||
const operatorAfter = appendChatNotice(operator, operatorNotice);
|
||||
const throwawayAfter = appendChatNotice(throwaway, throwawayNotice);
|
||||
assert.deepEqual(operatorAfter, [operatorNotice]);
|
||||
assert.deepEqual(throwawayAfter, [throwawayNotice]);
|
||||
assert.deepEqual(dismissChatNotice(operatorAfter, "notice-1"), []);
|
||||
assert.deepEqual(throwawayAfter, [throwawayNotice]);
|
||||
const taken = takeChatNoticeOffer(
|
||||
appendChatNotice(throwawayAfter, makeChatNotice("notice-3", "Offer", { offer: "/help" })),
|
||||
"notice-3",
|
||||
);
|
||||
assert.equal(taken.offer, "/help");
|
||||
assert.deepEqual(operatorAfter, [operatorNotice]);
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Slash commands (C9)
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -1507,3 +1653,282 @@ test("a step that ends does not clear a background shell that outlives the turn"
|
||||
assert.equal(resumed.selectedShellId, null);
|
||||
assert.equal(resumed.shellOutput, null);
|
||||
});
|
||||
|
||||
// ---- The create flow's directory picker (C2, ChatDirectories.kt) -----------
|
||||
|
||||
test("directoryChoices makes the first non-blank directory home and keeps recents in server order", () => {
|
||||
const choices = directoryChoices(["/Users/alan", "", "/work/one", " ", "/work/two"]);
|
||||
assert.deepEqual(choices, [
|
||||
{
|
||||
label: "Home (~)",
|
||||
path: "/Users/alan",
|
||||
home: true,
|
||||
createDirectory: "~",
|
||||
secondary: "/Users/alan",
|
||||
},
|
||||
{
|
||||
label: "/work/one",
|
||||
path: "/work/one",
|
||||
home: false,
|
||||
createDirectory: "/work/one",
|
||||
secondary: null,
|
||||
},
|
||||
{
|
||||
label: "/work/two",
|
||||
path: "/work/two",
|
||||
home: false,
|
||||
createDirectory: "/work/two",
|
||||
secondary: null,
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
test("directoryChoices always yields home first, even for an empty or blank reply", () => {
|
||||
for (const reply of [[], ["", " "], null, undefined]) {
|
||||
const choices = directoryChoices(reply);
|
||||
assert.equal(choices.length, 1);
|
||||
assert.deepEqual(choices[0], {
|
||||
label: HOME_LABEL,
|
||||
path: HOME_DIRECTORY,
|
||||
home: true,
|
||||
createDirectory: HOME_DIRECTORY,
|
||||
secondary: HOME_DIRECTORY,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
test("the home row is the only one with a secondary path; recents are labelled by full path", () => {
|
||||
const choices = directoryChoices(["/home/operator", "/repo/a", "/repo/b"]);
|
||||
assert.deepEqual(
|
||||
choices.map((choice) => [choice.label, choice.secondary]),
|
||||
[
|
||||
["Home (~)", "/home/operator"],
|
||||
["/repo/a", null],
|
||||
["/repo/b", null],
|
||||
],
|
||||
);
|
||||
assert.equal(defaultDirectoryChoice(choices)?.label, HOME_LABEL);
|
||||
assert.equal(defaultDirectoryChoice([]), null);
|
||||
});
|
||||
|
||||
test("newChatCreateState starts on home, not sending, with the caller's operation id", () => {
|
||||
assert.deepEqual(newChatCreateState("web-chat-op"), {
|
||||
directory: HOME_DIRECTORY,
|
||||
operationId: "web-chat-op",
|
||||
creating: false,
|
||||
error: "",
|
||||
});
|
||||
});
|
||||
|
||||
test("selectChatDirectory sends the chosen value and clears a previous refusal", () => {
|
||||
const state = { ...newChatCreateState("op"), error: "refused" };
|
||||
const recent = { label: "/repo/a", path: "/repo/a", home: false, createDirectory: "/repo/a", secondary: null };
|
||||
assert.deepEqual(selectChatDirectory(state, recent), {
|
||||
directory: "/repo/a",
|
||||
operationId: "op",
|
||||
creating: false,
|
||||
error: "",
|
||||
});
|
||||
assert.equal(selectChatDirectory(state, "~").directory, "~");
|
||||
assert.deepEqual(selectChatDirectory(state, ""), state);
|
||||
});
|
||||
|
||||
test("chatCreateFailed keeps the pane open with the server's message; success stops sending", () => {
|
||||
const creating = { ...newChatCreateState("op"), creating: true };
|
||||
assert.deepEqual(chatCreateFailed(creating, "the directory is not available"), {
|
||||
directory: "~",
|
||||
operationId: "op",
|
||||
creating: false,
|
||||
error: "the directory is not available",
|
||||
});
|
||||
});
|
||||
|
||||
test("chatCreateSucceeded puts the created session at the head and dedupes by id", () => {
|
||||
const a = { id: "a", title: "A" };
|
||||
const b = { id: "b", title: "B" };
|
||||
const created = { id: "b", title: "New chat" };
|
||||
assert.deepEqual(chatCreateSucceeded([a, b], created), [created, a]);
|
||||
assert.deepEqual(chatCreateSucceeded([], created), [created]);
|
||||
assert.deepEqual(chatCreateSucceeded([a], null), [a]);
|
||||
});
|
||||
|
||||
test("the create flow's wording is the app's verbatim", () => {
|
||||
assert.equal(CHAT_CREATE_TITLE, "Start a chat");
|
||||
assert.equal(CHAT_CREATE_BACK_LABEL, "Cancel new chat");
|
||||
assert.equal(CHAT_CREATE_LOADING, "Loading directories…");
|
||||
assert.equal(CHAT_CREATE_PROMPT, "Where should this chat live?");
|
||||
assert.equal(
|
||||
CHAT_CREATE_MODEL_NOTE,
|
||||
"This server has no request for choosing a chat's model, so a new chat uses the server's default.",
|
||||
);
|
||||
assert.equal(CHAT_CREATE_CONFIRM, "New chat");
|
||||
assert.equal(CHAT_CREATE_CANCEL, "Cancel");
|
||||
assert.equal(chatStartInLabel(HOME_DIRECTORY), "Start in ~");
|
||||
assert.equal(chatStartInLabel("/repo/a"), "Start in /repo/a");
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// C13: the local overrides and the seen state (ChatOverrides.kt / ChatSeen.kt)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
const sess = (id, title, updated_at) => ({ id, title, updated_at });
|
||||
|
||||
test("local overrides: a local title wins on every refresh, trimmed, blanks ignored", () => {
|
||||
const sessions = [sess("a", "Server A", 100), sess("b", "Server B", 200)];
|
||||
|
||||
// No overrides: the server's own list is returned untouched.
|
||||
assert.equal(applyChatOverrides(sessions, emptyChatOverrides()), sessions);
|
||||
|
||||
let overrides = renameChatOverride(emptyChatOverrides(), "a", " My A ");
|
||||
assert.deepEqual(overrides.titles, { a: "My A" });
|
||||
const applied = applyChatOverrides(sessions, overrides);
|
||||
assert.equal(applied[0].title, "My A");
|
||||
assert.equal(applied[1].title, "Server B");
|
||||
// A later refresh (the server's own title still "Server A") keeps the local name.
|
||||
assert.equal(applyChatOverrides(sessions, overrides)[0].title, "My A");
|
||||
|
||||
// A blank id or a blank/whitespace title changes nothing (identity preserved).
|
||||
assert.equal(renameChatOverride(overrides, "a", " "), overrides);
|
||||
assert.equal(renameChatOverride(overrides, " ", "Nope"), overrides);
|
||||
// A rename for another id is recorded without touching the first.
|
||||
const both = renameChatOverride(overrides, "b", "Bee");
|
||||
assert.deepEqual(both.titles, { a: "My A", b: "Bee" });
|
||||
assert.equal(applyChatOverrides(sessions, both)[1].title, "Bee");
|
||||
// Re-recording the same trimmed title is a no-op (same object).
|
||||
assert.equal(renameChatOverride(both, "b", " Bee "), both);
|
||||
});
|
||||
|
||||
test("hide + undo: one entry per id, blank ignored, restore returns the prior state", () => {
|
||||
const overrides = emptyChatOverrides();
|
||||
const hidden = hideChatOverride(overrides, "s1");
|
||||
assert.deepEqual(hidden.hidden, ["s1"]);
|
||||
// Already hidden: nothing changes, and no duplicate is appended.
|
||||
assert.equal(hideChatOverride(hidden, "s1"), hidden);
|
||||
assert.equal(hideChatOverride(hidden, " "), hidden);
|
||||
|
||||
const sessions = [sess("s1", "One", 1), sess("s2", "Two", 2)];
|
||||
assert.deepEqual(applyChatOverrides(sessions, hidden).map((s) => s.id), ["s2"]);
|
||||
|
||||
const restored = restoreChatOverride(hidden, "s1");
|
||||
assert.deepEqual(restored.hidden, []);
|
||||
assert.deepEqual(applyChatOverrides(sessions, restored).map((s) => s.id), ["s1", "s2"]);
|
||||
// Restoring something that was never hidden changes nothing.
|
||||
assert.equal(restoreChatOverride(restored, "s9"), restored);
|
||||
// Hide then undo returns the original model.
|
||||
assert.deepEqual(restoreChatOverride(hideChatOverride(overrides, "s1"), "s1"), overrides);
|
||||
});
|
||||
|
||||
test("overrides JSON round-trips, and unreadable/wrong-typed input decodes to empty", () => {
|
||||
const overrides = renameChatOverride(hideChatOverride(emptyChatOverrides(), "gone"), "kept", "Name");
|
||||
assert.deepEqual(decodeChatOverrides(encodeChatOverrides(overrides)), overrides);
|
||||
|
||||
for (const corrupt of [null, "", "not json", "{", "[]", '"x"', "42"]) {
|
||||
assert.deepEqual(decodeChatOverrides(corrupt), emptyChatOverrides());
|
||||
}
|
||||
// Wrong-typed fields fall back to the empty model rather than throwing.
|
||||
assert.deepEqual(decodeChatOverrides('{"titles":[],"hidden":"x"}'), emptyChatOverrides());
|
||||
assert.deepEqual(decodeChatOverrides('{"titles":{"a":3},"hidden":[7,"ok","ok"]}').hidden, ["ok"]);
|
||||
assert.deepEqual(decodeChatOverrides('{"titles":{"":"x","b":" B "}}'), { titles: { b: "B" }, hidden: [] });
|
||||
});
|
||||
|
||||
test("seen JSON round-trips, de-duplicates unseen, and tolerates corrupt input", () => {
|
||||
let seen = markChatUnseen(emptyChatSeen(), "s1");
|
||||
seen = markChatUnseen(seen, "s1"); // duplicate
|
||||
seen = readChatSeen(seen, "s2", 500);
|
||||
const decoded = decodeChatSeen(encodeChatSeen(seen));
|
||||
assert.deepEqual(decoded.seenAt, { s2: 500 });
|
||||
assert.deepEqual(decoded.unseen, ["s1"]);
|
||||
|
||||
for (const corrupt of [null, "", "not json", "{", "[]", "true"]) {
|
||||
assert.deepEqual(decodeChatSeen(corrupt), emptyChatSeen());
|
||||
}
|
||||
assert.deepEqual(decodeChatSeen('{"seenAt":[],"unseen":"x"}'), emptyChatSeen());
|
||||
const tolerated = decodeChatSeen('{"seenAt":{"a":10,"b":"x","":5},"unseen":["u","u",""]}');
|
||||
assert.deepEqual(tolerated.seenAt, { a: 10 });
|
||||
assert.deepEqual(tolerated.unseen, ["u"]);
|
||||
});
|
||||
|
||||
test("first sight seeding: a baseline is set once and never clears an explicit unseen", () => {
|
||||
const sessions = [sess("a", "A", 100), sess("b", "B", 0)];
|
||||
const seeded = seedChatSeen(emptyChatSeen(), sessions, null);
|
||||
assert.deepEqual(seeded.seenAt, { a: 100 });
|
||||
// An absent or zero recency is never recorded.
|
||||
assert.equal(seeded.seenAt.b, undefined);
|
||||
// A later, higher recency is not re-seeded over the existing baseline.
|
||||
const later = seedChatSeen(seeded, [sess("a", "A", 300)], null);
|
||||
assert.deepEqual(later.seenAt, { a: 100 });
|
||||
|
||||
// Seeding never clears an unseen mark.
|
||||
const marked = markChatUnseen(seeded, "a");
|
||||
const reseeded = seedChatSeen(marked, [sess("a", "A", 400)], null);
|
||||
assert.deepEqual(reseeded.unseen, ["a"]);
|
||||
|
||||
// The active session is read (watermark advances, the mark clears).
|
||||
const active = seedChatSeen(markChatUnseen(emptyChatSeen(), "a"), [sess("a", "A", 900)], "a");
|
||||
assert.deepEqual(active.seenAt, { a: 900 });
|
||||
assert.deepEqual(active.unseen, []);
|
||||
});
|
||||
|
||||
test("reading advances the watermark monotonically and always clears the mark", () => {
|
||||
const first = readChatSeen(emptyChatSeen(), "s", 100);
|
||||
assert.equal(chatSeenWatermark(first, "s"), 100);
|
||||
// A stale read cannot rewind it...
|
||||
assert.equal(readChatSeen(first, "s", 50), first);
|
||||
// ...an equal read is not "newer" either...
|
||||
assert.equal(readChatSeen(first, "s", 100), first);
|
||||
// ...but a strictly newer one advances.
|
||||
assert.equal(chatSeenWatermark(readChatSeen(first, "s", 101), "s"), 101);
|
||||
|
||||
// A mark is cleared even when the recency does not advance.
|
||||
const marked = markChatUnseen(first, "s");
|
||||
const read = readChatSeen(marked, "s", 100);
|
||||
assert.deepEqual(read.unseen, []);
|
||||
assert.equal(read.seenAt.s, 100);
|
||||
// A blank id is a no-op.
|
||||
assert.equal(readChatSeen(first, " ", 500), first);
|
||||
});
|
||||
|
||||
test("the unseen rule: not active, explicit mark or never-opened-and-strictly-newer", () => {
|
||||
let seen = readChatSeen(emptyChatSeen(), "opened", 100);
|
||||
seen = readChatSeen(seen, "equal", 100);
|
||||
// A watermark ahead of the session's own recency: not newer, so not new.
|
||||
seen = readChatSeen(seen, "old", 120);
|
||||
const opened = sess("opened", "Opened", 200); // moved on after it was read
|
||||
const fresh = sess("fresh", "Fresh", 150);
|
||||
const equal = sess("equal", "Equal", 100);
|
||||
const old = sess("old", "Old", 50);
|
||||
|
||||
// The active session is never new, even with an explicit mark.
|
||||
assert.equal(
|
||||
isChatSessionUnseen(opened, { activeId: "opened", seen: markChatUnseen(seen, "opened"), opened: true }),
|
||||
false,
|
||||
);
|
||||
// A never-opened session is new only while strictly newer than the watermark.
|
||||
assert.equal(isChatSessionUnseen(fresh, { seen, opened: false }), true);
|
||||
assert.equal(isChatSessionUnseen(equal, { seen, opened: false }), false);
|
||||
assert.equal(isChatSessionUnseen(old, { seen, opened: false }), false);
|
||||
// A session already opened here is judged by the explicit mark alone.
|
||||
assert.equal(isChatSessionUnseen(opened, { seen, opened: true }), false);
|
||||
assert.equal(isChatSessionUnseen(opened, { seen: markChatUnseen(seen, "opened"), opened: true }), true);
|
||||
});
|
||||
|
||||
test("the C13 wording matches the Android sources verbatim", () => {
|
||||
assert.equal(CHAT_RENAME_ACTION, "Rename…");
|
||||
assert.equal(CHAT_HIDE_ACTION, "Hide on this device");
|
||||
assert.equal(CHAT_ACTIONS_LABEL, "Chat actions");
|
||||
assert.equal(CHAT_REMOVED_MESSAGE, "Hidden on this device; the chat stays on the server.");
|
||||
assert.equal(CHAT_UNDO_ACTION, "Undo");
|
||||
assert.equal(CHAT_RENAME_TITLE, "Rename chat");
|
||||
assert.equal(CHAT_RENAME_FIELD_LABEL, "Name");
|
||||
assert.equal(
|
||||
CHAT_RENAME_HELPER,
|
||||
"The server has no rename for a chat, so this name is kept on this device.",
|
||||
);
|
||||
assert.equal(CHAT_RENAME_SAVE, "Save");
|
||||
assert.equal(CHAT_RENAME_DISMISS, "Cancel");
|
||||
// The badge precedence words, with Open only while the conversation is open.
|
||||
assert.equal(sessionActivityBadge(sessionActivity(true, true), true), "Streaming");
|
||||
assert.equal(sessionActivityBadge(sessionActivity(false, true), true), "New");
|
||||
assert.equal(sessionActivityBadge(sessionActivity(false, false), true), "Open");
|
||||
assert.equal(sessionActivityBadge(sessionActivity(false, false), false), null);
|
||||
});
|
||||
|
||||
@@ -0,0 +1,214 @@
|
||||
// The pure notification model (L5): qualifying transitions, exactly-once
|
||||
// dedupe, pre-existing/dismissed suppression, the app's exact wording and the
|
||||
// total permission/storage helpers. No DOM, no timer, no live server.
|
||||
import { test } from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
|
||||
import { AttentionKind, attentionKey } from "../src/attention.js";
|
||||
import {
|
||||
NOTIFICATION_DEFAULT,
|
||||
NOTIFICATION_DEFAULT_ASKED,
|
||||
NOTIFICATION_DENIED,
|
||||
NOTIFICATION_GRANTED,
|
||||
NOTIFICATION_INSECURE,
|
||||
NOTIFICATION_UNSUPPORTED,
|
||||
NOTIFY_STORAGE_KEY,
|
||||
alertBody,
|
||||
alertKey,
|
||||
alertTitle,
|
||||
createAlertLedger,
|
||||
decodeNotificationSettings,
|
||||
encodeNotificationSettings,
|
||||
notificationEnvironment,
|
||||
notificationPermissionState,
|
||||
} from "../src/notify.js";
|
||||
|
||||
const frame = (runId, status, extra = {}) => ({
|
||||
run_id: runId,
|
||||
status,
|
||||
name: "release",
|
||||
title: "Ship it",
|
||||
...extra,
|
||||
});
|
||||
|
||||
test("headlines are exactly the app's two, and unknown kinds are blank", () => {
|
||||
assert.equal(alertTitle(AttentionKind.Failed), "A run failed");
|
||||
assert.equal(alertTitle(AttentionKind.Decision), "A run needs your decision");
|
||||
assert.equal(alertTitle({ name: "Failed" }), "A run failed");
|
||||
assert.equal(alertTitle({ name: "Other" }), "");
|
||||
});
|
||||
|
||||
test("the alert identity is the attention identity", () => {
|
||||
assert.equal(alertKey(7, AttentionKind.Failed), attentionKey(7, AttentionKind.Failed));
|
||||
assert.equal(alertKey(7, AttentionKind.Decision), "7:Decision");
|
||||
});
|
||||
|
||||
test("alert body is the title then the pipeline, with the pipeline fallback", () => {
|
||||
assert.equal(alertBody({ label: "Ship it", pipeline: "release" }), "Ship it \u00b7 release");
|
||||
assert.equal(alertBody({ title: " Ship it ", name: "release" }), "Ship it \u00b7 release");
|
||||
assert.equal(alertBody({ title: " ", name: "release" }), "release");
|
||||
assert.equal(alertBody({ label: "release", pipeline: "release" }), "release");
|
||||
assert.equal(alertBody({ label: "Ship it", pipeline: "" }), "Ship it");
|
||||
assert.equal(alertBody(frame(7, "failed")), "Ship it \u00b7 release");
|
||||
});
|
||||
|
||||
test("queued -> failed raises one alert and duplicate frames never repeat it", () => {
|
||||
const ledger = createAlertLedger();
|
||||
ledger.seed([{ id: 4, status: "queued", name: "release", title: "Ship it" }]);
|
||||
const alert = ledger.observe(frame(4, "failed"));
|
||||
assert.equal(alert.title, "A run failed");
|
||||
assert.equal(alert.body, "Ship it \u00b7 release");
|
||||
assert.equal(alert.key, "4:Failed");
|
||||
assert.equal(ledger.observe(frame(4, "failed")), null);
|
||||
assert.equal(ledger.observe(frame(4, "failed")), null);
|
||||
});
|
||||
|
||||
test("running -> waiting raises the decision alert; unchanged waiting raises none", () => {
|
||||
const ledger = createAlertLedger();
|
||||
ledger.seed([{ id: 9, status: "running", name: "release", title: "Ship it" }]);
|
||||
const alert = ledger.observe(frame(9, "waiting"));
|
||||
assert.equal(alert.title, "A run needs your decision");
|
||||
assert.equal(alert.key, "9:Decision");
|
||||
assert.equal(ledger.observe(frame(9, "waiting")), null);
|
||||
});
|
||||
|
||||
test("succeeded, canceled, interrupted and unknown statuses raise nothing", () => {
|
||||
for (const status of ["succeeded", "canceled", "interrupted", "mystery", ""]) {
|
||||
const ledger = createAlertLedger();
|
||||
ledger.seed([{ id: 11, status: "running" }]);
|
||||
assert.equal(ledger.observe(frame(11, status)), null, `status ${status}`);
|
||||
}
|
||||
});
|
||||
|
||||
test("a first-seen failed/waiting run (a snapshot seed) raises nothing", () => {
|
||||
const ledger = createAlertLedger();
|
||||
assert.equal(ledger.observe(frame(21, "failed")), null);
|
||||
assert.equal(ledger.observe(frame(22, "waiting")), null);
|
||||
});
|
||||
|
||||
test("a run already failed/waiting in the seed raises nothing", () => {
|
||||
const ledger = createAlertLedger();
|
||||
ledger.seed([
|
||||
{ id: 31, status: "failed" },
|
||||
{ id: 32, status: "waiting" },
|
||||
]);
|
||||
assert.equal(ledger.observe(frame(31, "failed")), null);
|
||||
assert.equal(ledger.observe(frame(32, "waiting")), null);
|
||||
});
|
||||
|
||||
test("the subscribe snapshot is seeded, so a queued run that failed in the gap does not notify", () => {
|
||||
const ledger = createAlertLedger();
|
||||
ledger.seed([{ id: 41, status: "queued" }]);
|
||||
ledger.beginSeed();
|
||||
assert.equal(ledger.observe(frame(41, "failed")), null);
|
||||
ledger.endSeed();
|
||||
assert.equal(ledger.observe(frame(41, "failed")), null);
|
||||
// A later real transition still raises exactly once.
|
||||
assert.equal(ledger.observe(frame(41, "running")), null);
|
||||
assert.equal(ledger.observe(frame(41, "failed")).key, "41:Failed");
|
||||
});
|
||||
|
||||
test("leaving the qualifying state forgets the key for a genuinely new transition", () => {
|
||||
const ledger = createAlertLedger();
|
||||
ledger.seed([{ id: 51, status: "queued" }]);
|
||||
assert.equal(ledger.observe(frame(51, "failed")).key, "51:Failed");
|
||||
assert.equal(ledger.observe(frame(51, "running")), null);
|
||||
assert.equal(ledger.observe(frame(51, "failed")).key, "51:Failed");
|
||||
// And a failed -> waiting hand-off raises the other kind once.
|
||||
assert.equal(ledger.observe(frame(51, "waiting")).key, "51:Decision");
|
||||
assert.equal(ledger.observe(frame(51, "waiting")), null);
|
||||
});
|
||||
|
||||
test("a dismissed attention key notifies nothing, even on a real transition", () => {
|
||||
const ledger = createAlertLedger();
|
||||
ledger.seed([{ id: 61, status: "queued" }]);
|
||||
const alert = ledger.observe(frame(61, "failed"), {
|
||||
dismissed: new Set([attentionKey(61, AttentionKind.Failed)]),
|
||||
});
|
||||
assert.equal(alert, null);
|
||||
assert.deepEqual(ledger.notifiedKeys(), ["61:Failed"]);
|
||||
});
|
||||
|
||||
test("reset drops the status baseline but keeps the page session's dedupe", () => {
|
||||
const ledger = createAlertLedger();
|
||||
ledger.seed([{ id: 71, status: "queued" }]);
|
||||
assert.equal(ledger.observe(frame(71, "failed")).key, "71:Failed");
|
||||
ledger.reset();
|
||||
// Re-seeding the fresh (still failed) list is not a transition.
|
||||
ledger.seed([{ id: 71, status: "failed" }]);
|
||||
assert.equal(ledger.observe(frame(71, "failed")), null);
|
||||
assert.deepEqual(ledger.notifiedKeys(), ["71:Failed"]);
|
||||
});
|
||||
|
||||
test("a malformed frame is ignored, never crashed on", () => {
|
||||
const ledger = createAlertLedger();
|
||||
assert.equal(ledger.observe(null), null);
|
||||
assert.equal(ledger.observe({}), null);
|
||||
assert.equal(ledger.observe({ run_id: 0, status: "failed" }), null);
|
||||
});
|
||||
|
||||
test("permission wording is honest for every browser state", () => {
|
||||
assert.equal(notificationPermissionState({ supported: false }).body, NOTIFICATION_UNSUPPORTED);
|
||||
assert.equal(
|
||||
notificationPermissionState({ supported: true, secureContext: false }).body,
|
||||
NOTIFICATION_INSECURE,
|
||||
);
|
||||
assert.equal(notificationPermissionState({ permission: "denied" }).body, NOTIFICATION_DENIED);
|
||||
assert.equal(notificationPermissionState({ permission: "granted" }).body, NOTIFICATION_GRANTED);
|
||||
assert.equal(notificationPermissionState({ asked: false }).body, NOTIFICATION_DEFAULT);
|
||||
assert.equal(notificationPermissionState({ asked: true }).body, NOTIFICATION_DEFAULT_ASKED);
|
||||
});
|
||||
|
||||
test("only a supported, secure default permission offers the request control", () => {
|
||||
const defaultView = notificationPermissionState({ asked: false });
|
||||
assert.equal(defaultView.state, "default");
|
||||
assert.equal(defaultView.canRequest, true);
|
||||
assert.equal(defaultView.actionLabel, "Enable notifications");
|
||||
|
||||
for (const options of [
|
||||
{ supported: false },
|
||||
{ supported: true, secureContext: false },
|
||||
{ permission: "granted" },
|
||||
{ permission: "denied" },
|
||||
]) {
|
||||
const view = notificationPermissionState(options);
|
||||
assert.equal(view.canRequest, false, JSON.stringify(options));
|
||||
assert.equal(view.actionLabel, null, JSON.stringify(options));
|
||||
}
|
||||
// Having been asked once does not remove the control while permission stays
|
||||
// default (the browser itself decides whether it may prompt again).
|
||||
assert.equal(notificationPermissionState({ asked: true }).canRequest, true);
|
||||
});
|
||||
|
||||
test("the asked flag round-trips and malformed storage decodes safely", () => {
|
||||
assert.equal(NOTIFY_STORAGE_KEY, "pipelines.web.notify.v1");
|
||||
const stored = encodeNotificationSettings({ asked: true });
|
||||
assert.deepEqual(JSON.parse(stored), { asked: true });
|
||||
assert.equal(decodeNotificationSettings(stored).asked, true);
|
||||
assert.equal(decodeNotificationSettings(encodeNotificationSettings({ asked: false })).asked, false);
|
||||
|
||||
for (const bad of ["", " ", "not json", "[]", "null", '"asked"', "{", '{"asked":"yes"}', "42"]) {
|
||||
assert.deepEqual(decodeNotificationSettings(bad), { asked: false }, bad);
|
||||
}
|
||||
assert.deepEqual(decodeNotificationSettings(null), { asked: false });
|
||||
});
|
||||
|
||||
test("notificationEnvironment reads the browser facts without guessing", () => {
|
||||
const granted = notificationEnvironment({
|
||||
Notification: Object.assign(function Notification() {}, { permission: "granted" }),
|
||||
isSecureContext: true,
|
||||
});
|
||||
assert.deepEqual(granted, { supported: true, secureContext: true, permission: "granted" });
|
||||
|
||||
assert.deepEqual(notificationEnvironment({}), {
|
||||
supported: false,
|
||||
secureContext: false,
|
||||
permission: "default",
|
||||
});
|
||||
|
||||
const odd = notificationEnvironment({
|
||||
Notification: Object.assign(function Notification() {}, { permission: "maybe" }),
|
||||
isSecureContext: false,
|
||||
});
|
||||
assert.deepEqual(odd, { supported: true, secureContext: false, permission: "default" });
|
||||
});
|
||||
@@ -293,6 +293,30 @@ test("a run action throws when the reply has no run detail", async () => {
|
||||
await assert.rejects(() => repo.cancelRun(7), ProtocolError);
|
||||
});
|
||||
|
||||
test("subscribeRuns sends exactly the blank any-workspace watch and no run_ids", async () => {
|
||||
const { repo, ws } = connected();
|
||||
ws.reply = (frame) => ({ id: frame.id, type: "subscribe" });
|
||||
|
||||
await repo.subscribeRuns();
|
||||
assert.deepEqual(lastFrame(ws), { type: "subscribe", workspace: "" });
|
||||
});
|
||||
|
||||
test("unsubscribeRuns sends exactly {type:'unsubscribe'}", async () => {
|
||||
const { repo, ws } = connected();
|
||||
ws.reply = (frame) => ({ id: frame.id, type: "unsubscribe" });
|
||||
|
||||
await repo.unsubscribeRuns();
|
||||
assert.deepEqual(lastFrame(ws), { type: "unsubscribe" });
|
||||
});
|
||||
|
||||
test("subscribeRuns is not sent while the page is not connected", async () => {
|
||||
FakeWebSocket.instances = [];
|
||||
const client = new PipelinesClient({ WebSocketImpl: FakeWebSocket });
|
||||
const repo = new PipelinesRepository(client);
|
||||
await assert.rejects(() => repo.subscribeRuns(), { name: "NotConnectedError" });
|
||||
assert.equal(FakeWebSocket.instances.length, 0);
|
||||
});
|
||||
|
||||
// ---- The composer's own commands (C8/C9) ----------------------------------
|
||||
|
||||
test("chatPrompt trims the text, sends the operation and native message ids, and omits files when empty", async () => {
|
||||
@@ -345,6 +369,41 @@ test("chatInterrupt sends the session as chat_query (not a chat_interrupt body)"
|
||||
assert.deepEqual(lastFrame(ws), { type: "chat_interrupt", chat_query: { session_id: "s1" } });
|
||||
});
|
||||
|
||||
test("chatDirectories sends exactly {type:'chat_directories'} and returns the list", async () => {
|
||||
const { repo, ws } = connected();
|
||||
const directories = ["/home/operator", "/repo/one", "/repo/two"];
|
||||
ws.reply = (frame) => ({ id: frame.id, type: "chat_directories", chat_directories: directories });
|
||||
|
||||
assert.deepEqual(await repo.chatDirectories(), directories);
|
||||
assert.deepEqual(lastFrame(ws), { type: "chat_directories" });
|
||||
});
|
||||
|
||||
test("chatDirectories returns [] when the reply carries no directories", async () => {
|
||||
const { repo, ws } = connected();
|
||||
ws.reply = (frame) => ({ id: frame.id, type: "chat_directories" });
|
||||
assert.deepEqual(await repo.chatDirectories(), []);
|
||||
});
|
||||
|
||||
test("chatDirectories surfaces a server refusal as a ProtocolError", async () => {
|
||||
const { repo, ws } = connected();
|
||||
ws.reply = (frame) => ({ id: frame.id, type: "error", error: "unknown command: chat_directories" });
|
||||
await assert.rejects(() => repo.chatDirectories(), {
|
||||
name: "ProtocolError",
|
||||
message: "unknown command: chat_directories",
|
||||
});
|
||||
});
|
||||
|
||||
test("chatCreate sends home as ~ and carries the exact title/directory/operation_id body", async () => {
|
||||
const { repo, ws } = connected();
|
||||
ws.reply = (frame) => ({ id: frame.id, type: "chat_create", chat_session: { id: "ses_new" } });
|
||||
|
||||
await repo.chatCreate("New chat", "~", "op-4");
|
||||
assert.deepEqual(lastFrame(ws), {
|
||||
type: "chat_create",
|
||||
chat_create: { title: "New chat", directory: "~", operation_id: "op-4" },
|
||||
});
|
||||
});
|
||||
|
||||
test("chatCreate sends title/directory/operation_id and returns chat_session", async () => {
|
||||
const { repo, ws } = connected();
|
||||
const created = { id: "ses_new", title: "New chat" };
|
||||
|
||||
+1132
-36
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user