Drop the hybrid prefer gate and the gate weight from remote.js distribute
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
680744278a
commit
fbc0f16c4a
2 files changed
+37
-26
No files matched your search
+13
-14
@@ -1,6 +1,6 @@
|
||||
/* 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
|
||||
* how an agent's gates share out between the Where block and Other rules. No
|
||||
* how an agent's gates share out between the fetch gate's blocks and Other rules. 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
|
||||
@@ -60,10 +60,11 @@
|
||||
return [...EUROPE, ...countries.filter((c) => !EUROPE.includes(c))];
|
||||
}
|
||||
|
||||
/** Share out an agent's gates between the Where block and Other rules. Each
|
||||
Where line takes the first gate it can say whole; the rest are rows. A
|
||||
must or one-of gate with a weight other than the default stays a row,
|
||||
since Where would drop it.
|
||||
/** 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
|
||||
gate it can say whole; the rest are rows. A gate has a field, values and
|
||||
a mode (require, any, exclude) and no weight; a gate with a mode the
|
||||
form does not know, such as an old prefer, stays a row.
|
||||
|
||||
The scope line is the first plain require gate on country: `europe`
|
||||
when it is exactly Europe and the countries line (`europeWith`),
|
||||
@@ -73,21 +74,19 @@
|
||||
scope), `from` for a one-of on `remote_from`, else `none`; when both
|
||||
are there `remote_from` wins and the plain one stays a row. */
|
||||
function distribute(gates) {
|
||||
const where = { scope: null, countries: null, places: null, remote: { mode: "none", values: [] }, hybrid: null, titles: null };
|
||||
const where = { scope: null, countries: null, places: null, remote: { mode: "none", values: [] }, titles: null };
|
||||
const rest = [];
|
||||
const plain = (g) => g.weight === undefined || g.weight === 1;
|
||||
const only = (g, value) => g.values.length === 1 && g.values[0] === value;
|
||||
let must = null;
|
||||
let older = null;
|
||||
let from = null;
|
||||
for (const g of gates) {
|
||||
if (g.field === "country" && g.mode === "require" && plain(g) && !must) must = g;
|
||||
else if (g.field === "country" && g.mode === "any" && plain(g) && !where.countries) where.countries = g;
|
||||
else if (g.field === "place" && g.mode === "any" && plain(g) && !where.places) where.places = g;
|
||||
else if (g.field === "remote_from" && g.mode === "any" && plain(g) && !from) from = g;
|
||||
else if (g.field === "remote" && g.mode === "any" && plain(g) && only(g, "remote") && !older) older = g;
|
||||
else if (g.field === "remote" && g.mode === "prefer" && only(g, "hybrid") && !where.hybrid) where.hybrid = g;
|
||||
else if (g.field === "title" && g.mode === "exclude" && plain(g) && !where.titles) where.titles = g;
|
||||
if (g.field === "country" && g.mode === "require" && !must) must = g;
|
||||
else if (g.field === "country" && g.mode === "any" && !where.countries) where.countries = g;
|
||||
else if (g.field === "place" && g.mode === "any" && !where.places) where.places = g;
|
||||
else if (g.field === "remote_from" && g.mode === "any" && !from) from = g;
|
||||
else if (g.field === "remote" && g.mode === "any" && only(g, "remote") && !older) older = g;
|
||||
else if (g.field === "title" && g.mode === "exclude" && !where.titles) where.titles = g;
|
||||
else rest.push(g);
|
||||
}
|
||||
if (from) {
|
||||
|
||||
+24
-12
@@ -57,7 +57,6 @@ test("the sentence lists the areas, and says anywhere in lower case", () => {
|
||||
|
||||
const older = { field: "remote", values: ["remote"], mode: "any" };
|
||||
const from = (...values) => ({ field: "remote_from", values, mode: "any" });
|
||||
const hybrid = { field: "remote", values: ["hybrid"], mode: "prefer", weight: 0.05 };
|
||||
const dk = { field: "country", values: ["DK"], mode: "any" };
|
||||
const must = (...values) => ({ field: "country", values, mode: "require" });
|
||||
const europe = must(...rh.EUROPE);
|
||||
@@ -90,12 +89,27 @@ test("any other require gate on country is the scope with its codes as chips", (
|
||||
assert.deepEqual(rest, []);
|
||||
});
|
||||
|
||||
test("a second or weighted require gate on country stays a row", () => {
|
||||
test("a second require gate on country stays a row", () => {
|
||||
const second = must("NO");
|
||||
const weighted = { ...must("DE"), weight: 2 };
|
||||
const { where, rest } = rh.distribute([europe, second, weighted]);
|
||||
const { where, rest } = rh.distribute([europe, second]);
|
||||
assert.equal(where.scope.kind, "europe");
|
||||
assert.deepEqual(rest, [second, weighted]);
|
||||
assert.deepEqual(rest, [second]);
|
||||
});
|
||||
|
||||
test("the titles to leave out are the exclude gate on title, and any other exclude is a row", () => {
|
||||
const titles = { field: "title", values: ["account executive"], mode: "exclude" };
|
||||
const level = { field: "seniority", values: ["junior"], mode: "exclude" };
|
||||
const { where, rest } = rh.distribute([titles, level]);
|
||||
assert.equal(where.titles, titles);
|
||||
assert.deepEqual(rest, [level]);
|
||||
});
|
||||
|
||||
test("a gate with a mode the form does not know stays a row 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: [] });
|
||||
assert.equal("hybrid" in where, false);
|
||||
assert.deepEqual(rest, [prefer]);
|
||||
});
|
||||
|
||||
test("a require gate on another field is a row and leaves the scope everywhere", () => {
|
||||
@@ -106,11 +120,10 @@ test("a require gate on another field is a row and leaves the scope everywhere",
|
||||
});
|
||||
|
||||
test("remote, three modes: the plain gate is within the scope", () => {
|
||||
const scope = rh.distribute([older, hybrid]);
|
||||
const scope = rh.distribute([older]);
|
||||
assert.deepEqual(scope.where.remote, { mode: "scope", values: [] });
|
||||
assert.equal(scope.where.hybrid, hybrid);
|
||||
assert.deepEqual(scope.rest, []);
|
||||
assert.deepEqual(rh.distribute([hybrid]).where.remote, { mode: "none", values: [] });
|
||||
assert.deepEqual(rh.distribute([]).where.remote, { mode: "none", values: [] });
|
||||
const named = rh.distribute([from("country:DK", "region:oresund")]);
|
||||
assert.deepEqual(named.where.remote, { mode: "from", values: ["country:DK", "region:oresund"] });
|
||||
assert.deepEqual(named.rest, []);
|
||||
@@ -124,11 +137,10 @@ test("a remote_from gate wins over the plain one, which stays a row", () => {
|
||||
}
|
||||
});
|
||||
|
||||
test("a second remote_from gate, a weighted one or a must stays a row", () => {
|
||||
test("a second remote_from gate or a must stays a row", () => {
|
||||
const second = from("country:SE");
|
||||
const weighted = { ...from("country:DE"), weight: 2 };
|
||||
const required = { field: "remote_from", values: ["country:DK"], mode: "require" };
|
||||
const { where, rest } = rh.distribute([from("country:DK"), second, weighted, required]);
|
||||
const { where, rest } = rh.distribute([from("country:DK"), second, required]);
|
||||
assert.deepEqual(where.remote, { mode: "from", values: ["country:DK"] });
|
||||
assert.deepEqual(rest, [second, weighted, required]);
|
||||
assert.deepEqual(rest, [second, required]);
|
||||
});
|
||||
Reference in new issue
Block a user