mirror of
https://github.com/jparkerweb/plan2code.git
synced 2026-11-17 04:45:33 -08:00
Refuse a new console question while cards from the send just collected are still open and unsettled
AI Assisted
This commit is contained in:
1 parent
7f32c351b1
commit
d1aab9d006
4 files changed
+68
-1
No files matched your search
@@ -43,7 +43,7 @@ test("settle: true records the send wait handed over, never a later one still un
|
|||||||
assert.equal((await s.send("/submit", EXPORT_A)).status, 200);
|
assert.equal((await s.send("/submit", EXPORT_A)).status, 200);
|
||||||
assert.equal(waitFor(s).status, 0);
|
assert.equal(waitFor(s).status, 0);
|
||||||
assert.deepEqual(readState(s.session).collected.ids, ["q1"], "collecting records which cards the send carried");
|
assert.deepEqual(readState(s.session).collected.ids, ["q1"], "collecting records which cards the send carried");
|
||||||
postPatch(s, { items: [choice("q2")] });
|
postPatch(s, { settle: true, items: [choice("q2")] });
|
||||||
assert.equal((await s.send("/submit", { actions: [{ i: "q2", type: "answer", kind: "choice", k: "B" }], reply: "Question q2: B" })).status, 200);
|
assert.equal((await s.send("/submit", { actions: [{ i: "q2", type: "answer", kind: "choice", k: "B" }], reply: "Question q2: B" })).status, 200);
|
||||||
postPatch(s, { settle: true });
|
postPatch(s, { settle: true });
|
||||||
const items = readState(s.session).items;
|
const items = readState(s.session).items;
|
||||||
|
|||||||
@@ -1380,6 +1380,31 @@ test("rejects more than three open required questions", () => {
|
|||||||
assert.match(res.stderr, /open at once/);
|
assert.match(res.stderr, /open at once/);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// The Dead Code run left the first two questions open after they were
|
||||||
|
// answered, because the next post never settled them, and the page landed on
|
||||||
|
// the old card. A post that asks something new now has to deal with them.
|
||||||
|
test("refuses a new question while the cards just collected stay open and unsettled", () => {
|
||||||
|
const sent = { at: "2026-11-10T10:00:00.000Z", kind: "choice", k: "A" };
|
||||||
|
const base = {
|
||||||
|
collected: { at: sent.at, ids: ["q1"] },
|
||||||
|
items: [{ id: "q1", kind: "choice", title: "Where to look", body: "b", status: "open", required: true, options: [], thread: [], submitted: sent }],
|
||||||
|
};
|
||||||
|
const ask = { id: "q2", kind: "text", title: "What next", body: "b" };
|
||||||
|
assert.throws(() => applyPatch(base, { items: [ask] }), /item "q1" settle: .*settle/);
|
||||||
|
const settled = applyPatch(base, { settle: true, items: [ask] });
|
||||||
|
assert.equal(settled.items.find((i) => i.id === "q1").status, "answered", "settle: true closes the card just answered");
|
||||||
|
assert.doesNotThrow(() => applyPatch(base, { settle: ["q1"], items: [ask] }));
|
||||||
|
assert.doesNotThrow(() => applyPatch(base, { items: [{ id: "q1", stands: true }, ask] }), "stands keeps a card open on purpose");
|
||||||
|
assert.doesNotThrow(() => applyPatch(base, { items: [{ id: "q1", _delete: true }, ask] }), "a deleted card is dealt with");
|
||||||
|
assert.doesNotThrow(() => applyPatch(base, { items: [{ id: "q1", body: "reworded" }, ask] }), "a reworded card is a new question");
|
||||||
|
assert.doesNotThrow(() => applyPatch(base, { items: [{ id: "q1", status: "reopened", body: "asked again" }, ask] }), "a reopened card is asked again");
|
||||||
|
assert.doesNotThrow(() => applyPatch(base, { items: [{ id: "q1", answer: { k: "A" } }, ask] }), "the agent's own answer settles the card");
|
||||||
|
assert.doesNotThrow(() => applyPatch({ ...base, collected: { at: sent.at, ids: ["q9"] } }, { items: [ask] }), "an id that is no longer on the page holds nothing up");
|
||||||
|
assert.doesNotThrow(() => applyPatch(base, { items: [{ ...ask, required: false }] }), "an optional card asks nothing new");
|
||||||
|
assert.doesNotThrow(() => applyPatch(base, { items: [{ id: "n1", kind: "notice", title: "Heads up", body: "b" }] }), "a notice asks nothing");
|
||||||
|
assert.doesNotThrow(() => applyPatch(base, { finish: { headline: "Done", body: "b" }, items: [ask] }), "a finish is not held to it");
|
||||||
|
});
|
||||||
|
|
||||||
test("rejects internal vocabulary in a title", () => {
|
test("rejects internal vocabulary in a title", () => {
|
||||||
const p = { items: [{ id: "j1", kind: "text", title: "Frontier grill posture", body: "b", required: false }] };
|
const p = { items: [{ id: "j1", kind: "text", title: "Frontier grill posture", body: "b", required: false }] };
|
||||||
const res = cli(["post", "--session", sid, "--file", payload("jargon.json", p)], { expectFail: true });
|
const res = cli(["post", "--session", sid, "--file", payload("jargon.json", p)], { expectFail: true });
|
||||||
|
|||||||
@@ -89,6 +89,7 @@ After the person's note on an open question, reword it (same `id`), retire it wi
|
|||||||
- a doc `version` that goes back (leave `version` out)
|
- a doc `version` that goes back (leave `version` out)
|
||||||
- a finish `command` with `<` or `>` in it
|
- a finish `command` with `<` or `>` in it
|
||||||
- a note left without a reply
|
- a note left without a reply
|
||||||
|
- a new open required question while a card from the send you just collected is still open (add `"settle":true`, or reword, reopen, delete or `"stands":true` it)
|
||||||
- a `finish` while `stopWarning` is set or a helper is still `running`
|
- a `finish` while `stopWarning` is set or a helper is still `running`
|
||||||
- a `stop` with no `finish` (`stop --session <sid> --force` for a dead page)
|
- a `stop` with no `finish` (`stop --session <sid> --force` for a dead page)
|
||||||
|
|
||||||
|
|||||||
@@ -639,6 +639,7 @@ export function applyPatch(state, patch) {
|
|||||||
delete next.finish;
|
delete next.finish;
|
||||||
}
|
}
|
||||||
refuseQuestionPastNote(state, next);
|
refuseQuestionPastNote(state, next);
|
||||||
|
refuseQuestionPastAnswers(state, next, patch);
|
||||||
return stampTimes(state, settleAgent(next, patch, state));
|
return stampTimes(state, settleAgent(next, patch, state));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -677,6 +678,46 @@ function refuseQuestionPastNote(before, next) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The cards the person just sent (`state.collected.ids`, written when `wait`
|
||||||
|
* handed the send over) are the agent's to settle. A patch that asks a new
|
||||||
|
* question while one of them is still open, untouched and unsettled, leaves
|
||||||
|
* two cards in front of the person, and the page can land on the old, already
|
||||||
|
* answered one (seen in the Dead Code skill: the first and second questions
|
||||||
|
* stayed in the list after they were answered). So the patch that adds a new
|
||||||
|
* open required question must also settle each of them (`settle: true`),
|
||||||
|
* reword it, reopen it, delete it or say it `stands`. A finish ends the
|
||||||
|
* session and the dashboard draws no cards, so neither is held to it.
|
||||||
|
*/
|
||||||
|
function refuseQuestionPastAnswers(before, next, patch) {
|
||||||
|
if (next.finish != null || next.workflow === "dashboard" || !Array.isArray(next.items)) return;
|
||||||
|
const ids = Array.isArray(before.collected?.ids) ? before.collected.ids : [];
|
||||||
|
if (!ids.length) return;
|
||||||
|
const had = new Set((Array.isArray(before.items) ? before.items : []).map((i) => i && i.id));
|
||||||
|
const asksNew = next.items.some(
|
||||||
|
(i) => isPlainObject(i) && !had.has(i.id) && i.required !== false && i.kind !== "notice" && isOpen(i),
|
||||||
|
);
|
||||||
|
if (!asksNew) return;
|
||||||
|
// `stands` keeps a card open on purpose; an `answer` in the patch is the agent settling it with its own reading (see settleItems).
|
||||||
|
const dealt = new Set((patch.items || []).filter((e) => isPlainObject(e) && (e.stands === true || "answer" in e)).map((e) => e.id));
|
||||||
|
const left = next.items.filter(
|
||||||
|
(i) => isPlainObject(i) && ids.includes(i.id) && i.kind !== "notice" && isOpen(i) && isPlainObject(i.submitted) && !dealt.has(i.id),
|
||||||
|
);
|
||||||
|
if (!left.length) return;
|
||||||
|
throw new Error(
|
||||||
|
left
|
||||||
|
.map((i) =>
|
||||||
|
rule(
|
||||||
|
`item "${i.id}"`,
|
||||||
|
"settle",
|
||||||
|
'was answered in the send you just collected and is still open: settle it in the same patch that adds a new question, with "settle": true (or a list of ids), or reword it, reopen it ("status": "reopened"), delete it ("_delete": true) or send "stands": true',
|
||||||
|
{ settle: true },
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.join("\n"),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// The person had the last word in a card's thread: their note waits for a reply.
|
// The person had the last word in a card's thread: their note waits for a reply.
|
||||||
function lastWordIsTheirs(item) {
|
function lastWordIsTheirs(item) {
|
||||||
const thread = Array.isArray(item.thread) ? item.thread : [];
|
const thread = Array.isArray(item.thread) ? item.thread : [];
|
||||||
|
|||||||
Reference in new issue
Block a user