Merge the agent form without Advanced rules: the gates are the four parts of the fetch gate, a stored gate the form cannot say is named and kept (wp-advanced)
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
commit
2262cda8f1
7 files changed
+193
-125
No files matched your search
@@ -0,0 +1,85 @@
|
||||
// static/agents.js without a browser: the gates Save sends from the fetch
|
||||
// gate's four parts, and the stored gates the parts cannot say, which the
|
||||
// form names in a note and sends back as they came.
|
||||
//
|
||||
// node --test tests/js/*.test.mjs
|
||||
|
||||
import { test } from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { readFileSync } from "node:fs";
|
||||
import vm from "node:vm";
|
||||
|
||||
// Only what agents.js touches before DOMContentLoaded.
|
||||
const window = { api: async () => [], count: (n, noun) => `${n} ${noun}` };
|
||||
const document = { addEventListener() {} };
|
||||
Object.assign(globalThis, { window, document });
|
||||
for (const file of ["remote.js", "agents.js"]) {
|
||||
vm.runInThisContext(readFileSync(new URL(`../../app/static/${file}`, import.meta.url), "utf8"));
|
||||
}
|
||||
const rh = window.remoteHelpers;
|
||||
const { formGates, keptNote, rulesLine } = window.agentGates;
|
||||
|
||||
/** The four parts as the form shows them after loading `gates`, and what it keeps. */
|
||||
function load(gates) {
|
||||
const { where, rest } = rh.distribute(gates);
|
||||
const parts = {
|
||||
scope: where.scope.kind, scoped: where.scope.values,
|
||||
within: where.countries ? where.countries.values : [],
|
||||
towns: where.places ? where.places.values : [],
|
||||
remote: where.remote.mode, from: where.remote.values,
|
||||
titles: where.titles ? where.titles.values : [],
|
||||
};
|
||||
return { parts, rest };
|
||||
}
|
||||
|
||||
const europe = { field: "country", values: rh.europeWith(["DK"]), mode: "require" };
|
||||
const dk = { field: "country", values: ["DK"], mode: "any" };
|
||||
const remote = { field: "remote", values: ["remote"], mode: "any" };
|
||||
const towns = { field: "place", values: ["Malmö", "Lund"], mode: "any" };
|
||||
const titles = { field: "title", values: ["account executive", "sales"], mode: "exclude" };
|
||||
const level = { field: "seniority", values: ["senior", "staff"], mode: "require" };
|
||||
const acme = { field: "company", values: ["acme"], mode: "exclude" };
|
||||
|
||||
test("a save sends the four parts back as they were loaded", () => {
|
||||
const agents = [
|
||||
[europe, dk, remote, towns, titles],
|
||||
[{ field: "country", values: ["DK", "SE"], mode: "require" },
|
||||
{ field: "remote_from", values: ["country:DK", "country:EU"], mode: "any" }, titles],
|
||||
[dk],
|
||||
[],
|
||||
];
|
||||
for (const gates of agents) {
|
||||
const { parts, rest } = load(gates);
|
||||
assert.deepEqual(rest, []);
|
||||
assert.deepEqual(formGates(parts, rest), gates);
|
||||
}
|
||||
});
|
||||
|
||||
test("each part sends its own gate, and an empty part none", () => {
|
||||
const parts = { scope: "everywhere", scoped: [], within: [], towns: [], remote: "none", from: [], titles: [] };
|
||||
assert.deepEqual(formGates(parts), []);
|
||||
// A remote line open to no area yet, or chosen countries with none picked, say nothing.
|
||||
assert.deepEqual(formGates({ ...parts, remote: "from", scope: "countries" }), []);
|
||||
assert.deepEqual(formGates({ ...parts, scope: "europe", within: ["US"] }), [
|
||||
{ field: "country", values: rh.europeWith(["US"]), mode: "require" },
|
||||
{ field: "country", values: ["US"], mode: "any" },
|
||||
]);
|
||||
});
|
||||
|
||||
test("a stored gate the parts cannot say is kept across a save, named in the note and on the card", () => {
|
||||
const gates = [europe, dk, remote, titles, level, acme];
|
||||
const { parts, rest } = load(gates);
|
||||
assert.deepEqual(rest, [level, acme]);
|
||||
assert.deepEqual(formGates(parts, rest), gates);
|
||||
assert.equal(keptNote(rest),
|
||||
"The form cannot edit these rules, and Save keeps them as stored: "
|
||||
+ "must: with seniority senior, staff; not: at acme.");
|
||||
const words = rulesLine(gates);
|
||||
assert.match(words, /Only roles with seniority senior, staff\./);
|
||||
assert.match(words, /Leaves out roles at acme\./);
|
||||
});
|
||||
|
||||
test("an agent with nothing to keep has no note", () => {
|
||||
assert.equal(keptNote([]), "");
|
||||
assert.equal(keptNote([level]), "The form cannot edit this rule, and Save keeps it as stored: must: with seniority senior, staff.");
|
||||
});
|
||||
@@ -1,5 +1,6 @@
|
||||
// static/remote.js without a browser: the badge, the suggestions the agent's
|
||||
// remote line offers, and how gates share out between Where and Other rules.
|
||||
// remote line offers, and how gates share out between the fetch gate and the
|
||||
// rest the form keeps as stored.
|
||||
//
|
||||
// node --test tests/js/*.test.mjs
|
||||
|
||||
@@ -89,14 +90,14 @@ test("any other require gate on country is the scope with its codes as chips", (
|
||||
assert.deepEqual(rest, []);
|
||||
});
|
||||
|
||||
test("a second require gate on country stays a row", () => {
|
||||
test("a second require gate on country is kept as stored", () => {
|
||||
const second = must("NO");
|
||||
const { where, rest } = rh.distribute([europe, second]);
|
||||
assert.equal(where.scope.kind, "europe");
|
||||
assert.deepEqual(rest, [second]);
|
||||
});
|
||||
|
||||
test("the titles to leave out are the exclude gate on title, and any other exclude is a row", () => {
|
||||
test("the titles to leave out are the exclude gate on title, and any other exclude is kept as stored", () => {
|
||||
const titles = { field: "title", values: ["account executive"], mode: "exclude" };
|
||||
const level = { field: "seniority", values: ["junior"], mode: "exclude" };
|
||||
const { where, rest } = rh.distribute([titles, level]);
|
||||
@@ -104,7 +105,7 @@ test("the titles to leave out are the exclude gate on title, and any other exclu
|
||||
assert.deepEqual(rest, [level]);
|
||||
});
|
||||
|
||||
test("a gate with a mode the form does not know stays a row and takes no Where line", () => {
|
||||
test("a gate with a mode the form does not know is kept as stored and takes no Where line", () => {
|
||||
const prefer = { field: "remote", values: ["hybrid"], mode: "prefer" };
|
||||
const { where, rest } = rh.distribute([prefer]);
|
||||
assert.deepEqual(where.remote, { mode: "none", values: [] });
|
||||
@@ -112,7 +113,7 @@ test("a gate with a mode the form does not know stays a row and takes no Where l
|
||||
assert.deepEqual(rest, [prefer]);
|
||||
});
|
||||
|
||||
test("a require gate on another field is a row and leaves the scope everywhere", () => {
|
||||
test("a require gate on another field is kept as stored and leaves the scope everywhere", () => {
|
||||
const level = { field: "seniority", values: ["senior"], mode: "require" };
|
||||
const { where, rest } = rh.distribute([level]);
|
||||
assert.equal(where.scope.kind, "everywhere");
|
||||
@@ -129,7 +130,7 @@ test("remote, three modes: the plain gate is within the scope", () => {
|
||||
assert.deepEqual(named.rest, []);
|
||||
});
|
||||
|
||||
test("a remote_from gate wins over the plain one, which stays a row", () => {
|
||||
test("a remote_from gate wins over the plain one, which is kept as stored", () => {
|
||||
for (const gates of [[older, from("country:DK")], [from("country:DK"), older]]) {
|
||||
const { where, rest } = rh.distribute(gates);
|
||||
assert.deepEqual(where.remote, { mode: "from", values: ["country:DK"] });
|
||||
@@ -137,7 +138,7 @@ test("a remote_from gate wins over the plain one, which stays a row", () => {
|
||||
}
|
||||
});
|
||||
|
||||
test("a second remote_from gate or a must stays a row", () => {
|
||||
test("a second remote_from gate or a must is kept as stored", () => {
|
||||
const second = from("country:SE");
|
||||
const required = { field: "remote_from", values: ["country:DK"], mode: "require" };
|
||||
const { where, rest } = rh.distribute([from("country:DK"), second, required]);
|
||||
|
||||
+29
-1
@@ -998,7 +998,13 @@ def test_the_agents_page_lists_and_edits_search_agents(client: TestClient) -> No
|
||||
template = page[page.index('<template id="agent-form-template">'):page.index("</template>")]
|
||||
assert 'id="agent-form"' in template and 'id="a-cancel"' in template
|
||||
assert 'id="a-name"' in page and 'placeholder="My search"' in page
|
||||
assert 'id="a-prompts"' in page and "<details" in page and 'id="a-gates"' in page
|
||||
assert 'id="a-prompts"' in page
|
||||
# The gates are the four parts and nothing else: no rows of other rules,
|
||||
# only a note naming a stored rule the parts cannot say.
|
||||
for gone in ("<details", 'id="a-gates"', 'id="a-rules"', 'id="a-add-rule"', "Other rules"):
|
||||
assert gone not in template
|
||||
assert template.index('id="a-where-sum"') < template.index('id="a-kept"') \
|
||||
< template.index("</fieldset>", template.index('id="a-where-sum"'))
|
||||
for weight in ("a-fit", "a-recency", "a-affinity", "a-taste"):
|
||||
assert f'id="{weight}"' in page
|
||||
assert 'id="a-taste" min="0" step="0.05" value="0.2"' in page
|
||||
@@ -1170,6 +1176,28 @@ def test_agents_are_created_updated_listed_and_deleted(client: TestClient) -> No
|
||||
assert client.delete(f"/api/agents/{agent['id']}").status_code == 404
|
||||
|
||||
|
||||
def test_an_agents_fetch_gate_and_a_rule_the_form_cannot_say_round_trip(client: TestClient) -> None:
|
||||
"""What the form sends for the four parts, plus a stored gate on a field the
|
||||
form has no part for, is served back as sent, so a load and a save keep it."""
|
||||
europe = ["AT", "BE", "BG", "HR", "CY", "CZ", "DK", "EE", "FI", "FR", "DE", "GR", "HU", "IE",
|
||||
"IT", "LV", "LT", "LU", "MT", "NL", "PL", "PT", "RO", "SK", "SI", "ES", "SE", "IS",
|
||||
"LI", "NO", "GB", "CH", "EU"]
|
||||
gates = [{"field": "country", "values": europe, "mode": "require"},
|
||||
{"field": "country", "values": ["DK"], "mode": "any"},
|
||||
{"field": "remote_from", "values": ["country:DK", "anywhere"], "mode": "any"},
|
||||
{"field": "place", "values": ["Malmö"], "mode": "any"},
|
||||
{"field": "title", "values": ["account executive"], "mode": "exclude"},
|
||||
{"field": "seniority", "values": ["senior"], "mode": "require"}]
|
||||
body = {"name": "Nordics", "prompts": [{"name": "Data", "text": "Head of Data"}],
|
||||
"gates": gates, "fetch_terms": ["data"]}
|
||||
agent = client.post("/api/agents", json=body).json()
|
||||
assert agent["gates"] == gates and agent["fetch_terms"] == ["data"]
|
||||
served = next(a for a in client.get("/api/agents").json() if a["id"] == agent["id"])
|
||||
assert served["gates"] == gates
|
||||
again = client.post("/api/agents", json={**body, "id": agent["id"], "gates": served["gates"]})
|
||||
assert again.status_code == 200 and again.json()["gates"] == gates
|
||||
|
||||
|
||||
def test_agents_take_and_serve_prompts_and_still_take_an_intent(client: TestClient) -> None:
|
||||
prompts = [{"name": "AI and data leadership", "text": "VP, Head or Director of AI"},
|
||||
{"name": "Forward deployed", "text": ""}]
|
||||
|
||||
Reference in new issue
Block a user