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:
WolfandClaude Fable 5.1 committed 2026-10-06 14:34:11 +02:00
commit 2262cda8f1
7 files changed
+193 -125

No files matched your search

+54 -83
View File
@@ -9,13 +9,15 @@
* ADR's order: the world (the scope select), the location (a short list of * ADR's order: the world (the scope select), the location (a short list of
* lines a role passes by matching any one of: countries, towns, remote), the * lines a role passes by matching any one of: countries, towns, remote), the
* role exclusion (the titles to leave out) and the role fetch (the fetch * role exclusion (the titles to leave out) and the role fetch (the fetch
* terms), over a row per remaining rule under Advanced; a gate the four parts * terms), and nothing else: seniority, pay and the like are filters on Roles.
* cannot say lands in a row, so a load and a save lose nothing. A gate is a * A gate is a field, values and a mode (must, one of, not), with no weight.
* field, values and a mode (must, one of, not), with no weight. After it come * A stored gate the four parts cannot say, which only the config or the API
* the analytics filter (the best N by prompt closeness and the best M by CV * writes, is named in a note under the fetch gate and sent back as it came,
* closeness, each with a minimum level), the want feed score weights (prompt * so a load and a save lose nothing. After the fetch gate come the analytics
* closeness, newness, company like, job like), the CV match weights and the * filter (the best N by prompt closeness and the best M by CV closeness, each
* size of summarise. Edit turns a card * with a minimum level), the want feed score weights (prompt closeness,
* newness, company like, job like), the CV match weights and the size of
* summarise. Edit turns a card
* into the form from the page's `<template>`, in place, and New agent puts a * into the form from the page's `<template>`, in place, and New agent puts a
* blank card on top in the same state. One card edits at a time, so the * blank card on top in the same state. One card edits at a time, so the
* form's ids stay unique. Votes, liked companies and scores are the agent's, * form's ids stay unique. Votes, liked companies and scores are the agent's,
@@ -61,9 +63,8 @@
const NEW = "new"; const NEW = "new";
// Europe as the starter agents spell it (static/remote.js). // Europe as the starter agents spell it (static/remote.js).
const EUROPE = rh.EUROPE; const EUROPE = rh.EUROPE;
const FIELDS = ["place", "country", "remote", "remote_from", "seniority", "function", "salary_min", // A gate's mode in the words of the note on the gates the form keeps.
"currency", "permit", "languages", "company", "title"]; const MODES = { require: "must", any: "one of", exclude: "not" };
const MODES = [["require", "must"], ["any", "one of"], ["exclude", "not"]];
/** @type {object[]} every agent, as the server lists them */ /** @type {object[]} every agent, as the server lists them */
let agents = []; let agents = [];
@@ -263,8 +264,8 @@
} }
// The region and place in words, one sentence led by the region, then the lines a // The region and place in words, one sentence led by the region, then the lines a
// role may match, with the one-of rows among them since they are the same // role may match, with any other one-of gates among them since they are the
// group: "Within Europe: keeps roles anywhere in Denmark, in Malmö, Lund or // same group: "Within Europe: keeps roles anywhere in Denmark, in Malmö, Lund or
// Helsingborg, or remote, and leaves out the rest." The lines add up, which // Helsingborg, or remote, and leaves out the rest." The lines add up, which
// the first wording ("Roles in ...") left the owner to guess. // the first wording ("Roles in ...") left the owner to guess.
function whereSentence(where, others) { function whereSentence(where, others) {
@@ -381,7 +382,7 @@
// ---------------------------------------------------------------- the form // ---------------------------------------------------------------- the form
// Tell the form something changed that no field typed: a chip or a row // Tell the form something changed that no field typed: a chip or a row
// added or removed. It marks the form dirty and redraws the gates view. // added or removed. It marks the form dirty and redraws the gates' sentence.
function changed(node) { function changed(node) {
node.dispatchEvent(new Event("input", { bubbles: true })); node.dispatchEvent(new Event("input", { bubbles: true }));
} }
@@ -556,9 +557,9 @@
return box; return box;
} }
// A language as a row, after the rule rows: a code, a level, Remove. The // A language as a row: a code, a level, Remove. The code is two letters,
// code is two letters, which the server turns into the language; its name // which the server turns into the language; its name is the row's title
// is the row's title where the browser knows it. // where the browser knows it.
function languageRow(language, remove) { function languageRow(language, remove) {
const row = el("div", "rule-row"); const row = el("div", "rule-row");
const code = el("input"); const code = el("input");
@@ -584,32 +585,32 @@
return { node: row, read: () => ({ language: code.value.trim().toLowerCase(), level: level.value }) }; return { node: row, read: () => ({ language: code.value.trim().toLowerCase(), level: level.value }) };
} }
// A gate as a row: field, mode, values and Remove. Values untouched since the load are sent as they came, so a // The gates the fetch gate's four parts say, in the order the starter
// value with a comma in it survives a save. // agents have them: the world, the location lines and the titles left out,
function ruleRow(gate, remove) { // then `kept`, the stored gates the parts cannot say, as they came. `parts`
const row = el("div", "rule-row"); // holds what the form reads: `scope` (europe, countries, everywhere) and
const field = select(FIELDS.map((f) => [f, f.replace("_", " ")]), gate.field, "Field"); // its `scoped` countries, the `within` countries, the `towns`, `remote`
const mode = select(MODES, gate.mode, "Mode"); // (none, scope, from) and its `from` areas, and the `titles`.
const values = el("input"); function formGates(parts, kept = []) {
values.type = "text"; const out = [];
values.required = true; const { scope, scoped, within, towns: lines, remote, from, titles } = parts;
values.spellcheck = false; if (scope === "europe") out.push({ field: "country", values: rh.europeWith(within), mode: "require" });
values.placeholder = "senior, staff"; if (scope === "countries" && scoped.length) out.push({ field: "country", values: scoped, mode: "require" });
values.value = gate.values.join(", "); if (within.length) out.push({ field: "country", values: within, mode: "any" });
values.setAttribute("aria-label", "Values, separated by commas"); if (remote === "scope") out.push({ field: "remote", values: ["remote"], mode: "any" });
const loaded = values.value; if (remote === "from" && from.length) out.push({ field: "remote_from", values: from, mode: "any" });
const drop = linky("Remove"); if (lines.length) out.push({ field: "place", values: lines, mode: "any" });
drop.addEventListener("click", () => remove(row)); if (titles.length) out.push({ field: "title", values: titles, mode: "exclude" });
row.append(field, mode, values, drop); return out.concat(kept);
}
function read() { // The note on the gates the form keeps: "The form cannot edit these rules,
const parts = values.value === loaded // and Save keeps them as stored: must: with seniority senior; not: at Acme."
? gate.values function keptNote(kept) {
: values.value.split(",").map((v) => v.trim()).filter(Boolean) if (!kept.length) return "";
.map((v) => (field.value === "salary_min" ? Number(v) : v)); const said = kept.map((g) => `${MODES[g.mode] || g.mode}: ${phrase(g)}`).join("; ");
return { field: field.value, values: parts, mode: mode.value }; return `The form cannot edit ${kept.length > 1 ? "these rules" : "this rule"}, and Save keeps `
} + `${kept.length > 1 ? "them" : "it"} as stored: ${said}.`;
return { node: row, read };
} }
function form(row) { function form(row) {
@@ -710,51 +711,18 @@
remoteFrom.node.hidden = remoteMode.value !== "from"; remoteFrom.node.hidden = remoteMode.value !== "from";
}; };
offer(); offer();
$("details.advanced", f).open = rest.length > 0; const kept = $("#a-kept", f);
kept.textContent = keptNote(rest);
kept.hidden = !rest.length;
const rules = []; // The gates Save sends: the four parts', then the kept ones. The sentence
const dropRule = (node) => { // under them says them all, as the card will, the kept ones included.
rules.splice(rules.findIndex((r) => r.node === node), 1); const gates = () => formGates({
node.remove(); scope: scope.value, scoped: scoped.values(), within: countries.values(), towns: places.values(),
changed(f); remote: remoteMode.value, from: remoteFrom.values(), titles: titles.values(),
}; }, rest);
const addRule = (gate) => {
const entry = ruleRow(gate, dropRule);
rules.push(entry);
$("#a-rules", f).appendChild(entry.node);
return entry;
};
rest.forEach(addRule);
$("#a-add-rule", f).addEventListener("click", () => {
$("select", addRule({ field: "seniority", values: [], mode: "require" }).node).focus();
changed(f);
});
// The gates the fetch gate's three parts say, in the order the starter
// agents have them: the region, the place lines, and the titles left out.
function whereGates() {
const out = [];
const within = countries.values();
const towns = places.values();
const from = remoteFrom.values();
if (scope.value === "europe") out.push({ field: "country", values: rh.europeWith(within), mode: "require" });
if (scope.value === "countries" && scoped.values().length) {
out.push({ field: "country", values: scoped.values(), mode: "require" });
}
if (within.length) out.push({ field: "country", values: within, mode: "any" });
if (remoteMode.value === "scope") out.push({ field: "remote", values: ["remote"], mode: "any" });
if (remoteMode.value === "from" && from.length) out.push({ field: "remote_from", values: from, mode: "any" });
if (towns.length) out.push({ field: "place", values: towns, mode: "any" });
const left = titles.values();
if (left.length) out.push({ field: "title", values: left, mode: "exclude" });
return out;
}
// The gates Save sends: the fetch gate's, then the rows. The sentence
// under it says them all, as the card will, rows included.
const gates = () => whereGates().concat(rules.map((r) => r.read()));
const view = () => { const view = () => {
offer(); offer();
$("#a-gates", f).value = JSON.stringify(gates(), null, 2);
$("#a-where-sum", f).textContent = rulesLine(gates()) || "Passes every role."; $("#a-where-sum", f).textContent = rulesLine(gates()) || "Passes every role.";
}; };
view(); view();
@@ -978,6 +946,9 @@
} }
} }
// For tests/js/agents.test.mjs: what Save sends and how it is said.
window.agentGates = { formGates, keptNote, rulesLine };
document.addEventListener("DOMContentLoaded", async () => { document.addEventListener("DOMContentLoaded", async () => {
if (!$("#agents-list")) return; if (!$("#agents-list")) return;
$("#a-new").addEventListener("click", () => open(null)); $("#a-new").addEventListener("click", () => open(null));
+3 -9
View File
@@ -1300,8 +1300,6 @@ table.applications td[data-label="Saved"] { white-space: nowrap; color: var(--di
background: var(--bg); border: 1px solid var(--line); background: var(--bg); border: 1px solid var(--line);
border-radius: .3rem; padding: .35rem .5rem; width: 100%; border-radius: .3rem; padding: .35rem .5rem; width: 100%;
} }
/* Prose in a textarea is read in the page face; JSON is in the mono one. */
.agent-form textarea.code { font-family: var(--mono); font-size: .85rem; }
.agent-form .hint { color: var(--dim); font-size: .8rem; overflow-wrap: anywhere; } .agent-form .hint { color: var(--dim); font-size: .8rem; overflow-wrap: anywhere; }
.weights { display: flex; gap: .75rem; flex-wrap: wrap; border: 1px solid var(--line); border-radius: .3rem; } .weights { display: flex; gap: .75rem; flex-wrap: wrap; border: 1px solid var(--line); border-radius: .3rem; }
/* A label that wraps to two lines pushes its box down; the boxes stay in line. */ /* A label that wraps to two lines pushes its box down; the boxes stay in line. */
@@ -1316,14 +1314,13 @@ table.applications td[data-label="Saved"] { white-space: nowrap; color: var(--di
} }
/* The fieldsets that hold rows: a column, the Add button under the rows. */ /* The fieldsets that hold rows: a column, the Add button under the rows. */
.agent-form fieldset.prompts, .agent-form fieldset.where, .agent-form fieldset.titles, .agent-form fieldset.prompts, .agent-form fieldset.where, .agent-form fieldset.titles,
.agent-form fieldset.terms, .agent-form fieldset.terms {
.agent-form fieldset.rules {
display: flex; flex-direction: column; align-items: stretch; gap: .5rem; min-width: 0; display: flex; flex-direction: column; align-items: stretch; gap: .5rem; min-width: 0;
border: 1px solid var(--line); border-radius: .3rem; border: 1px solid var(--line); border-radius: .3rem;
} }
.agent-form fieldset > button { align-self: flex-start; } .agent-form fieldset > button { align-self: flex-start; }
/* A prompt or a rule as a row of a list, after `.crow`: the name and Remove /* A prompt or a language as a row of a list, after `.crow`: the name and Remove
on line one, the text spanning the row under them. A rule row wraps like on line one, the text spanning the row under them. A language row wraps like
`.crow .board-edit`, so a phone takes it in two lines rather than scrolling. */ `.crow .board-edit`, so a phone takes it in two lines rather than scrolling. */
.prompt-row { .prompt-row {
display: grid; grid-template-columns: 1fr auto; align-items: center; display: grid; grid-template-columns: 1fr auto; align-items: center;
@@ -1353,9 +1350,6 @@ table.applications td[data-label="Saved"] { white-space: nowrap; color: var(--di
.agent-form .chips input[type="text"] { flex: 1 1 6rem; width: auto; min-width: 0; } .agent-form .chips input[type="text"] { flex: 1 1 6rem; width: auto; min-width: 0; }
.agent-form .chips select { flex: 0 1 12rem; min-width: 0; max-width: 100%; } .agent-form .chips select { flex: 0 1 12rem; min-width: 0; max-width: 100%; }
.chips .tag span { color: var(--faint); } .chips .tag span { color: var(--faint); }
.agent-form details summary { cursor: pointer; color: var(--dim); font-size: .9rem; }
.agent-form details[open] summary { margin-bottom: .5rem; }
.agent-form .advanced-body { display: flex; flex-direction: column; gap: .6rem; }
/* ================================================================ */ /* ================================================================ */
/* companies and sources — the Sources page's sections, */ /* companies and sources — the Sources page's sections, */
+12 -10
View File
@@ -1,7 +1,8 @@
/* Where a remote role may be worked from, as the pages say it: the words of /* Where a remote role may be worked from, as the pages say it: the words of
* the badge, the picks of the agent's "Remote, open to someone in" chips, and * the badge, the picks of the agent's "Remote, open to someone in" chips, and
* how an agent's gates share out between the fetch gate's blocks and Other rules. No * how an agent's gates share out between the fetch gate's blocks and the rest
* DOM in it, so `tests/js/remote.test.mjs` can walk it without a browser. * the form keeps as stored. No DOM in it, so `tests/js/remote.test.mjs` can
* walk it without a browser.
* *
* The area is a place token in three spellings, one per layer: `remote:<place * The area is a place token in three spellings, one per layer: `remote:<place
* token>` on the Roles rail and in the address, `<place token>` in a * token>` on the Roles rail and in the address, `<place token>` in a
@@ -61,18 +62,19 @@
} }
/** Share out an agent's gates between the fetch gate's blocks (region, /** Share out an agent's gates between the fetch gate's blocks (region,
place, titles to leave out) and Other rules. Each line takes the first place, titles to leave out) and the rest, which the form cannot edit
gate it can say whole; the rest are rows. A gate has a field, values and and keeps as stored. Each line takes the first gate it can say whole.
a mode (require, any, exclude) and no weight; a gate with a mode the A gate has a field, values and a mode (require, any, exclude) and no
form does not know, such as an old prefer, stays a row. weight; a gate with a mode the form does not know, such as an old
prefer, is in the rest.
The scope line is the first plain require gate on country: `europe` The scope line is the first plain require gate on country: `europe`
when it is exactly Europe and the countries line (`europeWith`), when it is exactly Europe and the countries line (`europeWith`),
`countries` with its codes as chips otherwise, `everywhere` when there `countries` with its codes as chips otherwise, `everywhere` when there
is none. Any other require gate on country is a row. The remote line is is none. Any other require gate on country is in the rest. The remote
`scope` for the one-of on `remote: [remote]` (remote, within the line is `scope` for the one-of on `remote: [remote]` (remote, within
scope), `from` for a one-of on `remote_from`, else `none`; when both the scope), `from` for a one-of on `remote_from`, else `none`; when
are there `remote_from` wins and the plain one stays a row. */ both are there `remote_from` wins and the plain one is in the rest. */
function distribute(gates) { function distribute(gates) {
const where = { scope: null, countries: null, places: null, remote: { mode: "none", values: [] }, titles: null }; const where = { scope: null, countries: null, places: null, remote: { mode: "none", values: [] }, titles: null };
const rest = []; const rest = [];
+2 -15
View File
@@ -74,6 +74,7 @@
</div> </div>
<span class="hint">Fetch terms, separated by a comma or Enter: <code>machine learning, data science</code> is two terms, and <code>machine learning</code> is searched as one. A host that takes a query sends only roles with one of the terms anywhere in the ad, but only for boards of 300 or more roles; smaller boards and other hosts are read whole. The terms are ignored after the fetch, since prompt closeness is the finer filter. Empty means no narrowing.</span> <span class="hint">Fetch terms, separated by a comma or Enter: <code>machine learning, data science</code> is two terms, and <code>machine learning</code> is searched as one. A host that takes a query sends only roles with one of the terms anywhere in the ad, but only for boards of 300 or more roles; smaller boards and other hosts are read whole. The terms are ignored after the fetch, since prompt closeness is the finer filter. Empty means no narrowing.</span>
<p id="a-where-sum" class="where-sum" role="status"></p> <p id="a-where-sum" class="where-sum" role="status"></p>
<p id="a-kept" class="hint" hidden></p>
</fieldset> </fieldset>
<fieldset class="terms cv"> <fieldset class="terms cv">
<legend>Your CV</legend> <legend>Your CV</legend>
@@ -94,7 +95,7 @@
<textarea id="a-like-text" rows="4" placeholder="Building a team from scratch, close work with the product side, small companies, a say in the roadmap"></textarea></label> <textarea id="a-like-text" rows="4" placeholder="Building a team from scratch, close work with the product side, small companies, a say in the roadmap"></textarea></label>
<label>What I don't like <label>What I don't like
<textarea id="a-avoid-text" rows="4" placeholder="Constant on-call, sales targets, large consultancies, open-plan offices"></textarea></label> <textarea id="a-avoid-text" rows="4" placeholder="Constant on-call, sales targets, large consultancies, open-plan offices"></textarea></label>
<span class="hint">The work, the workplace, situations; read by the judge for the career rating. Rules that must hold go under the fetch gate or Other rules instead.</span> <span class="hint">The work, the workplace, situations; read by the judge for the career rating. Rules that must hold go under the fetch gate instead.</span>
</fieldset> </fieldset>
<fieldset class="weights limits"> <fieldset class="weights limits">
<legend>Analytics filter</legend> <legend>Analytics filter</legend>
@@ -124,20 +125,6 @@
<label>Summarise the top <input type="number" id="a-summarise-top" min="0" step="5" value="30"> of each feed order</label> <label>Summarise the top <input type="number" id="a-summarise-top" min="0" step="5" value="30"> of each feed order</label>
</fieldset> </fieldset>
<span class="hint">Summarise writes a short summary and tags for the top N of What I'm looking for and the top N of What fits me, at most twice N roles, and for every role you liked or saved. It is no part of any score.</span> <span class="hint">Summarise writes a short summary and tags for the top N of What I'm looking for and the top N of What fits me, at most twice N roles, and for every role you liked or saved. It is no part of any score.</span>
<details class="advanced">
<summary>Advanced</summary>
<div class="advanced-body">
<fieldset class="rules">
<legend>Other rules</legend>
<div id="a-rules" class="rule-rows"></div>
<button type="button" id="a-add-rule" class="secondary">Add rule</button>
<span class="hint">Must: a role must meet it. One of: a role must meet one of these or a Place line. Not: a role that meets it is left out. Values are separated by commas; salary is a number.</span>
</fieldset>
<label>Rules as sent
<textarea id="a-gates" class="code" rows="6" spellcheck="false" readonly>[]</textarea>
<span class="hint">Read only: what Save sends as the agent's gates, from the fetch gate and Other rules.</span></label>
</div>
</details>
<div class="agent-actions"> <div class="agent-actions">
<button type="submit">Save and score</button> <button type="submit">Save and score</button>
<button type="button" id="a-cancel" class="secondary">Cancel</button> <button type="button" id="a-cancel" class="secondary">Cancel</button>
+85
View File
@@ -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.");
});
+8 -7
View File
@@ -1,5 +1,6 @@
// static/remote.js without a browser: the badge, the suggestions the agent's // 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 // 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, []); 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 second = must("NO");
const { where, rest } = rh.distribute([europe, second]); const { where, rest } = rh.distribute([europe, second]);
assert.equal(where.scope.kind, "europe"); assert.equal(where.scope.kind, "europe");
assert.deepEqual(rest, [second]); 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 titles = { field: "title", values: ["account executive"], mode: "exclude" };
const level = { field: "seniority", values: ["junior"], mode: "exclude" }; const level = { field: "seniority", values: ["junior"], mode: "exclude" };
const { where, rest } = rh.distribute([titles, level]); 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]); 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 prefer = { field: "remote", values: ["hybrid"], mode: "prefer" };
const { where, rest } = rh.distribute([prefer]); const { where, rest } = rh.distribute([prefer]);
assert.deepEqual(where.remote, { mode: "none", values: [] }); 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]); 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 level = { field: "seniority", values: ["senior"], mode: "require" };
const { where, rest } = rh.distribute([level]); const { where, rest } = rh.distribute([level]);
assert.equal(where.scope.kind, "everywhere"); 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, []); 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]]) { for (const gates of [[older, from("country:DK")], [from("country:DK"), older]]) {
const { where, rest } = rh.distribute(gates); const { where, rest } = rh.distribute(gates);
assert.deepEqual(where.remote, { mode: "from", values: ["country:DK"] }); 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 second = from("country:SE");
const required = { field: "remote_from", values: ["country:DK"], mode: "require" }; const required = { field: "remote_from", values: ["country:DK"], mode: "require" };
const { where, rest } = rh.distribute([from("country:DK"), second, required]); const { where, rest } = rh.distribute([from("country:DK"), second, required]);
+29 -1
View File
@@ -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>")] 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="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-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"): for weight in ("a-fit", "a-recency", "a-affinity", "a-taste"):
assert f'id="{weight}"' in page assert f'id="{weight}"' in page
assert 'id="a-taste" min="0" step="0.05" value="0.2"' 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 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: 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"}, prompts = [{"name": "AI and data leadership", "text": "VP, Head or Director of AI"},
{"name": "Forward deployed", "text": ""}] {"name": "Forward deployed", "text": ""}]