Docs and help for the hardened cycle; library entries linted at check; due counts what arrived since the last cycle; brief trimmed to fit 4+ learnings. done / next: fail-before proof, repeat runs, rehearsal

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
swaitsandClaude Sonnet 5.5 committed 2026-11-23 14:42:27 -07:00
1 parent 33427c0394
commit 08d6921fcb
6 files changed
+204 -50

No files matched your search

+16 -11
View File
@@ -233,22 +233,27 @@ Learnings recorded by a subagent are held as candidates until the parent's retro
`sisi learn --withdraw` takes an owner statement recorded by mistake out of delivery while
keeping it in history.
**Promotion** is the cycle, due by a counter. A cycle turns proposed learnings into
mechanisms in the user store: an enforced contract requirement, an enforced command check, a
library entry, a risk-table or routing adjustment, a benchmark case, or rule text. Changes to
sisi's own code are `tool` learnings: they go to the backlog and the contribution export.
**Promotion** is the cycle, due by a counter (what a cycle can act on, arrived since the last one). `sisi cycle`
prints a brief a cheap agent can act on alone (format with an example per action, every value, what happens to
each kind of action, at most eight learnings, at most 6,000 characters). A cycle turns proposed learnings into
mechanisms in the user store: an enforced contract requirement, an enforced command check, a library entry, a
risk-table or routing adjustment, a benchmark case, a sentence added to a rule (`rule-add`) or a whole rule
(`rule-replace`, the owner's). Changes to sisi's own code are `tool` learnings: status `backlog`, never in a
brief, they go to the contribution export. `sisi cycle check` runs nothing and lists every problem at once;
`sisi cycle apply`:
- **validates before promoting**. A command check is replayed on the commits of the unit it
came from where they are known (must fail before the fix, pass after). What cannot be
replayed is promoted as `unvalidated` and reported as such; it is never called validated.
- **validates before promoting**. A command check is replayed only between the two commits of the learning's
own record (its unit's start and closing commits), in an exported copy of each tree with no history and a
reduced environment, and must name a path the fix changed. It must fail before the fix and pass after. What
cannot be replayed is `unvalidated`, waits for the owner and is reported as such; it is never called validated.
- **commits** each change to the user store; revert is exact, as now.
- **refuses** to touch protected rules (`canon/protected.json`: the non-negotiable
constraints, verification before done, truthful reporting, this governance). Disabling a
rule, widening a scope to everything, or adding a command that runs in every project is
consequential: it is stored as pending and takes effect only after the owner's decision
(`sisi approve ID --yes|--no`, asked through the host's question dialog). `sisi approve`
refuses a decision made without a terminal unless a config setting allows relayed approval.
rule, replacing a whole rule, widening a scope to everything, or adding a command that runs in every
project is consequential: it is stored as pending (the learning is `pending-approval`) and takes effect
only after the owner's decision (`sisi approve ID --yes|--no`, asked through the host's question dialog).
`sisi approve` needs the word it prints typed at the controlling terminal, and the before-tool hook refuses an
agent's shell command that invokes it.
- **must act on flagged learnings**: see monitoring.
**Monitoring.** A recurrence after promotion counts against the learning. Two recurrences flag
+51 -27
View File
@@ -14,8 +14,9 @@ A learning record carries: id, title, source unit, observation (evidence and imp
root cause, the proposed change (description, mechanism type, scope, target), expected
effect, validation (method, benchmark, result), status, version, provenance (every unit
and project it was seen in) and confidence. Status moves through `observed`, `analyzed`,
`proposed`, `implemented`, `validated`, `promoted`, `monitored`, and may end `revised`,
`reverted` or `rejected`. Showings are never recorded: being printed is not evidence.
`proposed`, `pending-approval` (a decision waits for the owner), `backlog` (a change to sisi
itself), `implemented`, `validated`, `promoted`, `monitored`, and may end `revised`, `reverted`,
`rejected` or `merged` (into another learning). Showings are never recorded: being printed is not evidence.
## The retro
@@ -73,15 +74,25 @@ commit as the row; a row added by hand, or edited by hand, has no matching entry
## The cycle
Promotion is the cycle, due by a counter checked during normal use (no scheduler):
`sisi cycle` prints the brief for a cheap worker, which writes one JSON cycle file
(`sisi cycle help` is the format). Mechanism kinds a cycle can install in the user
store: an enforced contract requirement, an enforced command check (both in
`overlay/enforced.json`), a library entry (recipe or verifier), rule text, a risk-table
adjustment (`overlay/risk-adjustments.json`), a routing adjustment
(`overlay/routing-adjustments.json`), or a benchmark case
(`overlay/benchmarks/<name>.json`). `tool` learnings — changes to sisi's own code — are
refused by the cycle; they go to the tool list shown in the learning report and to the contribution export.
Promotion is the cycle, due by a counter checked during normal use (no scheduler): five learnings a cycle
can act on arrived since the last cycle, or, fourteen days after it, five still waiting. `sisi cycle` prints
the brief for a cheap worker that has nothing else to read: the complete file format with one filled example
per action, every enumerated value, what happens to each kind of action (takes effect, held for the owner,
refused), and at most eight learnings (flagged first, then the most recurrent, then the oldest), each with its
statement, origin project, source unit and whether commits are recorded, in at most 6,000 characters; what does
not fit waits for the next cycle. The worker writes one JSON cycle file. `sisi cycle check FILE` runs nothing
and lists every problem in the file at once, each with how to fix it; `sisi cycle apply FILE` prints what took
effect, what waits and what was refused in at most fifteen lines. Mechanism kinds a cycle can install in the
user store: an enforced contract requirement (`when` is a risk profile or a path glob: something the code
evaluates), an enforced command check (both in `overlay/enforced.json`), a library entry (recipe or verifier;
it is linted when the file is checked), `rule-add` (one or two sentences added to a named rule before its
`Why:`, naming what the addition shortens or saying nothing can be; the applied message prints the loaded
rulebook size before and after), `rule-replace` (the whole rule; always the owner's), a risk-table adjustment
(`overlay/risk-adjustments.json`), a routing adjustment (`overlay/routing-adjustments.json`), or a benchmark case
(`overlay/benchmarks/<name>.json`). A learning that should not be promoted is `reject`ed with a specific reason
(a generic one is refused) or `merge`d into the learning it repeats. `tool` learnings are never in a brief or in
"due": they have the status `backlog` from the moment they are recorded and go to the tool list in the learning
report and to the contribution export (`sisi promote --export`).
`sisi cycle apply FILE` treats the file as untrusted input and plans everything before writing anything —
the budget and every other check run first, and a refusal applies nothing. If applying then fails part-way
@@ -91,24 +102,34 @@ the budget and every other check run first, and a refusal applies nothing. If ap
the scope the learning has earned (`learning.earned_scope`: its origin project unless it earned more)
and the origin project. Enforced checks, risk and routing adjustments are filtered by project when read.
A scope or `every_project` flag in the cycle file is a request for more, never the gate.
- **Replay before promotion** (`evaluate.validate_command`, the one replay implementation). A command check
is run in a temporary git worktree at the before-commit and the after-commit, and is `validated` only
if it **ran and failed** before the fix (not exit 126/127, not a timeout, not killed by a signal; its
program, and a script given to an interpreter, must exist at *both* commits) and ran and passed after.
The repository must be the learning's origin project and on the trust list, and `before` must be an
ancestor of `after`; otherwise the result is `unvalidated`, with the reason. A replay that ran and
behaved wrongly refuses the whole cycle. Replay never touches the working tree.
- **Replay before promotion** (`evaluate.validate_command`, the one replay implementation). `check` never
executes anything from the file. `apply` replays a command check only between the two commits the learning's
own record holds (the start and closing commits of the unit it was found in, from the unit record, or the
commits stored with the finding; commits named in the file are ignored), in the learning's origin project, on
the trust list. Each run is in an exported copy of that commit's tree with no `.git` directory (the command
cannot read history), an environment of PATH, HOME (an empty directory) and LANG only, a time limit, and
the copy is deleted afterwards. The command must name a path that differs between the two trees, or it is
refused as vacuous. It is `validated` only if it **ran and failed** at the start (not exit 126/127, not a
timeout, not killed by a signal; its program, and a script given to an interpreter, must exist at *both*
commits) and ran and passed at the end, and `before` is an ancestor of `after`; a learning with no recorded
commits, or any other reason it cannot be shown, leaves it `unvalidated` and waiting for the owner. A replay
that ran and behaved wrongly refuses the whole cycle. Replay never touches the working tree.
- **Protected rules** (`canon/protected.json`) cannot be replaced or disabled by a cycle or by
`sisi overlay`. If the file cannot be read, no rule can be changed.
- **Consequential changes wait for the owner**: more scope than the learning earned; an enforced command
not proven by replay (or that would run outside its origin project); a risk pattern that lowers a
profile; any replacement or disabling of a rule; rule text or a library entry from a learning confined to
one project; `sisi overlay replace-rule` and `disable-rule`. They are stored as pending and take effect
only after `sisi approve ID --yes|--no`.
profile; any whole-rule replacement or disabling of a rule; a sentence added to a rule, or a library entry,
from a learning confined to one project; a mechanism for a project that no longer exists on disk;
`sisi overlay replace-rule` and `disable-rule`. They are stored as pending and take effect only after
`sisi approve ID --yes|--no`. While a decision waits, its learning is `pending-approval`; promoting it
again is refused, and so is a second change to a rule that has one waiting. If the owner refuses, the
learning is rejected, not proposed again.
- **`sisi approve`** with no arguments lists every waiting change in full: the command, the pattern and
profile, the rule text as a diff, why it needs the owner, and the replay result. A decision made without
a terminal (an agent, a script) is refused unless the user config sets `learning.agent_relayed_approval`;
every decision is recorded in `approvals.jsonl` (when, session, terminal or not, `relayed by an agent`).
profile, the rule text as a diff, why it needs the owner, and the replay result. A decision needs the word
`sisi approve ID --yes|--no` prints typed back at the controlling terminal device (never standard input), and
the before-tool hook refuses any shell command of an agent that invokes it; a process with no controlling
terminal is refused unless the user config sets `learning.agent_relayed_approval`. Every decision, and every
refused attempt, is recorded in `approvals.jsonl` (when, session, terminal or not, `relayed by an agent`).
Session start prints one line while a decision is waiting, telling the agent to ask the owner through
the host's question dialog and to give him the command to run himself. SECURITY.md says what this does and
does not guarantee.
@@ -117,13 +138,16 @@ the budget and every other check run first, and a refusal applies nothing. If ap
files and learning fields it changed. `sisi cycle revert [ID]` undoes exactly those: statements, findings
and recurrences recorded after the cycle survive, and a revert is refused if a later change touched the
same file.
- A learning that was validated but waits for the owner has status `validated`; once promoted and a unit in
its scope has closed, or it has recurred, `monitored`.
- A learning that was validated but waits for the owner is `pending-approval` with its validation result kept;
once promoted and a unit in its scope has closed, or it has recurred, `monitored`.
- An origin project is always the main repository's key, never a linked worktree's path; `sisi update` repairs
records and mechanisms written before that (and statuses: tool learnings to `backlog`, learnings with a
decision waiting to `pending-approval`).
## Monitoring
A recurrence after promotion counts against the learning (once per unit). Two flag it "not working";
the next cycle must revise or revert it. `sisi status --learning` prints
the next cycle must revise or revert it. `sisi status --learning` prints only
`learning.learning_report()`: per promoted learning the units in its own scope since promotion
(read from `units.jsonl` in the user store, one JSON object per line with `id`, `project`, `closed_at`,
`risk`; the file may not exist yet, which counts as none), the recurrences, whether it is validated or
+47 -10
View File
@@ -43,7 +43,8 @@ import copy, difflib, json, os, re, sys, time
from . import documents, evaluate, learning as L, overlay, paths, pdata
DUE_AFTER = 5 # proposed learnings waiting make a cycle due (a counter, checked in normal use)
DUE_AFTER = 5 # new learnings a cycle can act on make a cycle due (a counter, checked in normal use)
DUE_AFTER_DAYS = 14 # or, this long after the last cycle, the ones it left alone
MECHANISM_KINDS = ("contract-requirement", "command-check", "library", "rule-add", "rule-replace",
"risk", "routing", "benchmark")
GLOBAL_KINDS = ("rule-add", "rule-replace", "library") # they change what every project loads: reach is `user`
@@ -205,10 +206,43 @@ def proposed(rows=None):
and (r.get("proposed") or {}).get("mechanism") != "tool" and L.is_registered(r, ledger)]
def _age_days(ts):
import calendar
try:
return (time.time() - calendar.timegm(time.strptime(ts, "%Y-%m-%dT%H:%M:%SZ"))) / 86400.0
except (TypeError, ValueError):
return 0.0
def _num(lid):
m = re.match(r"L-(\d+)$", str(lid))
return int(m.group(1)) if m else 0
def due_count(rows=None):
"""How many learnings make a cycle due: those a cycle can act on that arrived since the last
cycle ran (a brief shows only a few, so what it left alone does not make the next cycle due by
itself), or, once the last cycle is DUE_AFTER_DAYS old, everything still waiting. Every
learning waiting is in the next brief, oldest first, whenever it runs."""
pr = proposed(rows)
done = [r for r in cycle_records() if not r.get("reverted") and r.get("ts")]
if not done:
return len(pr)
lastrec = max(done, key=lambda r: r["ts"])
last = lastrec["ts"]
if lastrec.get("learning_max"): # ids only grow: what has a higher number arrived after the cycle
new = [r for r in pr if _num(r["id"]) > lastrec["learning_max"]]
else:
new = [r for r in pr if str(r.get("created") or "") > last]
if len(new) < DUE_AFTER and len(pr) >= DUE_AFTER and _age_days(last) >= DUE_AFTER_DAYS:
return len(pr)
return len(new)
def due_notice(session=None):
"""Session-start lines: a cycle is due, and/or a decision waits for the owner. The callers
(tick, the gate) catch and log a failure; it is not hidden here."""
n = len(proposed())
n = due_count()
fl = len(L.flagged())
lines = []
if n >= DUE_AFTER or fl:
@@ -232,21 +266,22 @@ Actions (L-0000 stands for an id listed below):
{"action":"promote","learning":"L-0000","mechanism_kind":"contract-requirement","when":"src/auth/**","require_kind":"parsing"}
{"action":"promote","learning":"L-0000","mechanism_kind":"rule-add","rule_id":"deliver-fast","add":"One or two sentences.","shortens":"nothing: <why>"}
{"action":"promote","learning":"L-0000","mechanism_kind":"rule-replace","rule_id":"deliver-fast","rule_text":"## Title {#deliver-fast}\\n\\nBody.\\n\\nWhy: ...","shortens":"..."}
{"action":"promote","learning":"L-0000","mechanism_kind":"library","library_kind":"recipe","entry_text":"---\\nid: x\\n---\\n..."}
{"action":"promote","learning":"L-0000","mechanism_kind":"library","library_kind":"recipe","entry_text":"---\\nid: x\\ntitle: T\\napplies_to: when\\n---\\n## Done means\\n- ...\\n## Checks\\n- `verifier-id`\\n## Common false finishes\\n- ..."}
{"action":"promote","learning":"L-0000","mechanism_kind":"risk","pattern":"src/auth/**","profile":"critical"}
{"action":"promote","learning":"L-0000","mechanism_kind":"routing","kind":"impl","difficulty":2,"prefer":"worker-x"}
{"action":"promote","learning":"L-0000","mechanism_kind":"benchmark","name":"csv-import","case":{...}}
{"action":"reject","learning":"L-0000","why":"names the evidence: the retry loop in sync.py was already removed"}
{"action":"merge","learning":"L-0000","into":"L-9999","why":"same cause"} {"action":"revise"|"revert","learning":"L-0000","why":"..."}
Values: mechanism_kind @KINDS@; risk profile @PROFILES@; require_kind @REQKINDS@;
library_kind recipe|verifier; difficulty 1|2|3; when = a risk profile (that or higher) or a path glob.
library_kind recipe|verifier (Checks may cite only ids `sisi verifiers` lists); difficulty 1|2|3;
when = a risk profile (that or higher) or a path glob.
A command check: cmd must name a path the fix changed; apply replays it in a copy of the tree without .git, between the
commits recorded for the learning (never ones you write): it must fail at the start and pass at the end. No commits: it waits.
Takes effect at once: reject, merge, revise, revert; risk (not lowering), routing, benchmark, contract-requirement; a replayed
command check; rule-add and library only from a learning seen in 2 units in 2 projects.
Held for the owner: rule-replace, disable-rule, rule-add or library from a one-project learning, a command check that was not
replayed, risk that lowers a profile, scope beyond what was earned, a project gone from disk.
Refused (whole file, every reason listed): protected rules (@PROTECTED@), a vacuous or failed replay, a generic reject reason,
Refused (whole file, every reason listed): a rule not in the list below (protected), a vacuous or failed replay, a generic reject reason,
a learning acted on twice or already waiting, a rule with a change waiting, a rulebook over @BUDGET@, a flagged learning left out.
Rules you may change (id): @RULES@. Rulebook now @SIZE@. Adding to it means naming what it shortens, or "nothing: <why>".
"""
@@ -288,7 +323,6 @@ def format_text(base):
lines, chars = _book_size()
return (FORMAT.replace("@BASE@", base).replace("@KINDS@", "|".join(MECHANISM_KINDS))
.replace("@PROFILES@", "|".join(risk.PROFILES)).replace("@REQKINDS@", "|".join(_contract.KINDS))
.replace("@PROTECTED@", ", ".join(sorted(p for p in prot if p in {r["id"] for r in rules})))
.replace("@BUDGET@", "%d lines/%d characters" % (overlay.MAX_LINES, overlay.MAX_CHARS))
.replace("@RULES@", ids).replace("@SIZE@", "%d lines/%d characters" % (lines, chars)))
@@ -432,7 +466,7 @@ def _plan_rule(kind, a, rec, virtual_rules, reasons, n):
lid = rec["id"]
rid = a.get("rule_id")
_need(isinstance(rid, str) and overlay.ID_OK.match(rid), "%s for %s needs \"rule_id\": the id the brief lists" % (kind, lid))
_need(rid not in protected_rules(), "rule %r is protected (canon/protected.json); a cycle may not touch it" % rid)
_need(rid not in protected_rules(), "rule %r is protected (canon/protected.json); a cycle may not touch it. Pick a rule from the brief's list" % rid)
in_force = {r["id"]: r for r in overlay.effective()[1]}
if kind == "rule-add":
_need(rid in in_force or rid in virtual_rules, "no rule %r to add to (the brief lists the ids)" % rid)
@@ -530,7 +564,7 @@ def _plan_promote(a, rec, virtual_rules, run=True):
_need(eid is None or (isinstance(eid, str) and overlay.ID_OK.match(eid)), "entry_id for %s is not a plain id" % lid)
n["entry_id"], n["replacing"] = eid, bool(a.get("replacing"))
try:
n["entry_id"], _rel, _mine = overlay._put_entry(n["library_kind"], n["entry_text"], eid, n["replacing"])
n["entry_id"] = overlay.check_entry(n["library_kind"], n["entry_text"], eid, n["replacing"])
except overlay.OverlayError as e:
raise CycleError("library entry for %s: %s" % (lid, e))
if n["replacing"]:
@@ -593,7 +627,7 @@ def validate_doc(doc, rows, run=True):
rid = a.get("rule_id")
who += " (disable-rule %s)" % rid
_need(isinstance(rid, str) and rid, "disable-rule needs \"rule_id\"")
_need(rid not in protected_rules(), "rule %r is protected (canon/protected.json); a cycle may not touch it" % rid)
_need(rid not in protected_rules(), "rule %r is protected (canon/protected.json); a cycle may not touch it. Pick a rule from the brief's list" % rid)
_need(rid in _rule_known(), "no rule %r (the brief lists the ids)" % rid)
_need(rid not in wait_r and rid not in ruled, "rule %s already has a change %s; wait for the "
"owner's decision" % (rid, "waiting (%s)" % wait_r[rid] if rid in wait_r else "in this file"))
@@ -839,7 +873,9 @@ def _transact(label, fn):
failure part-way restores every file it changed."""
pdata.ensure()
before = _head()
rows_before = {r["id"]: {k: copy.deepcopy(r[k]) for k in CYCLE_FIELDS if k in r} for r in L.load_learnings()}
all_rows = L.load_learnings()
rows_before = {r["id"]: {k: copy.deepcopy(r[k]) for k in CYCLE_FIELDS if k in r} for r in all_rows}
learning_max = max([_num(r["id"]) for r in all_rows] or [0])
try:
lines, touched, added = fn()
except BaseException:
@@ -862,6 +898,7 @@ def _transact(label, fn):
cid = "cycle-%04d" % n
rec = {"id": cid, "label": label, "ts": L.now(), "before": before, "after": after, "lines": lines,
"changed": _changed(before, after) if before and after else [],
"learning_max": learning_max,
"rows_before": {i: rows_before[i] for i in touched if i in rows_before},
"pending_added": added}
pdata.write_text("cycles/%s.json" % cid, json.dumps(rec, indent=2, sort_keys=True) + "\n")
+2 -2
View File
@@ -22,8 +22,8 @@ LONG = {
'overlay': ' sisi overlay list|diff|add-rule|replace-rule|disable-rule|enable-rule|add-verifier|...|revert COMMIT\n learned changes to rules, verifiers and recipes; each one a commit in your personal repo',
'retro': " sisi retro print the unit's record and what stands out in it\n sisi retro --finding F --cause C --impact value|correctness|time|cost|attention --disposition promote|record|drop [--same-as ID | --new] [--target ID]\n record one finding; promote also needs --change, --mechanism,\n --expect and --validate; record needs --limits; drop needs --why-not;\n a match in scope is printed and attached as a recurrence (--new records\n a learning of its own); --target names the rule or recipe it concerns\n sisi retro --adopt ID a parent adopts a subagent's candidate learning, by id",
'lessons': ' sisi lessons [--json] | ID the learning records and their statuses; with an id (L-0007): that one learning in full',
'cycle': ' sisi cycle [due|apply FILE|check FILE|revert [ID]|help]\n turn proposed learnings into mechanisms (no scheduler:\n due-ness is a counter); apply validates and replays before\n promoting; help prints the cycle file format',
'approve': " sisi approve [ID --yes|--no] list, in full, the consequential changes waiting for the owner; decide one\n (in a terminal: an agent's --yes without one is refused)",
'cycle': ' sisi cycle [due|apply FILE|check FILE|revert [ID]|help]\n with no argument: the brief (file format, values, at most eight learnings) for the agent that\n turns proposed learnings into mechanisms; check lists every problem in the file and runs\n nothing; apply replays command checks in an exported copy, then applies (no scheduler:\n due-ness is a counter)',
'approve': " sisi approve [ID --yes|--no] list, in full, the consequential changes waiting for the owner; decide one\n (the owner types the word it prints, at the terminal; an agent's shell command is refused)",
'learn': ' sisi learn [--scope user|project] TEXT\n record an owner statement; it takes effect at once and\n `sisi oracle` prints it. Scope for other learnings is\n earned by evidence, never claimed\n sisi learn --withdraw ID --reason WHY\n take a statement recorded by mistake out of delivery (kept in history)',
'risk': ' sisi risk [--json] risk floor for the working-tree change, with reasons and\n what that profile requires',
'handover': " sisi handover [--all] | done ID --where PATH [--quote FRAGMENT]\n project-scope learnings waiting to be filed in this project's own docs or\n work list; done confirms one is filed (the named file must contain\n its key text) and removes it from the list",
+23
View File
@@ -596,6 +596,29 @@ def _lint_new(rel):
raise OverlayError("the file does not pass `sisi verifiers lint`:\n " + "\n ".join(b[len(p) + 2:] for b in bad))
def check_entry(kind, text, id=None, replacing=False):
"""Would put_entry succeed? The same checks, with the overlay put back exactly as it was and
nothing committed: a library entry that cannot pass `sisi verifiers lint` is found when the
cycle file is checked, not when the owner approves it. Returns the entry id."""
from . import pdata
id, rel, mine = _put_entry(kind, text, id, replacing)
d = lib_dir(kind)
existed = os.path.isdir(d)
with pdata.lock():
snap = _snapshot(d)
try:
for p in mine:
_remove(p)
_write(rel, text if text.endswith("\n") else text + "\n")
_lint_new(rel)
finally:
_restore(d, snap)
if not existed:
import shutil
shutil.rmtree(d, ignore_errors=True)
return id
def put_entry(kind, text, id=None, replacing=False):
id, rel, mine = _put_entry(kind, text, id, replacing)
with _txn("overlay: %s %s %s" % ("replace" if replacing else "add", kind, id)):
+65
View File
@@ -746,6 +746,28 @@ class Check(Base):
self.assertEqual(self.sisi("lessons", "show", "L-0001").stdout, one.stdout)
class Library(Base):
"""R-16-7, R-16-9 (items 8 and 9): a library entry that cannot pass lint is found by check, not by the owner."""
def test_an_entry_that_fails_lint_is_refused_at_check_and_the_overlay_is_untouched(self):
_contract(self)
self.retro(*PROMOTE[1:])
act = {"action": "promote", "learning": "L-0001", "mechanism_kind": "library", "library_kind": "recipe",
"entry_id": "my-recipe", "entry_text": "---\nid: my-recipe\n---\n# T\n\nbody\n"}
r = self.sisi("cycle", "check", self.cycle_file([act]))
self.assertEqual(r.returncode, 2)
for frag in ("does not pass `sisi verifiers lint`", "missing or empty 'title'", "'applies_to'", "Done means"):
self.assertIn(frag, r.stderr)
self.assertFalse(self.exists("overlay/done"))
good = ("---\nid: my-recipe\ntitle: My recipe\napplies_to: work on the importer\n---\n\n## Done means\n- It is checked.\n\n"
"## Checks\n- Runs: `check-the-checker` (test-quality), rung 3.\n\n## Common false finishes\n- Not run.\n")
r = self.sisi("cycle", "check", self.cycle_file([dict(act, entry_text=good)]))
self.assertEqual(r.returncode, 0, r.stderr)
self.assertFalse(self.exists("overlay/done")) # check changed nothing
self.assertEqual(self.apply([dict(act, entry_text=good)]).returncode, 0)
self.assertEqual(len(self.pending()), 1) # a one-project learning's library entry waits
class Brief(Base):
"""R-11.1-14, R-11.5-4, R-16-10 (item 8): a small model can act on the brief alone."""
@@ -845,3 +867,46 @@ class Brief(Base):
r = self.sisi("cycle", "check", p)
self.assertEqual(r.returncode, 0, r.stderr)
self.assertEqual(self.sisi("cycle", "apply", p).returncode, 0)
class DueCounter(Base):
"""R-11.5-4, R-14.4-1 (item 4): due is a counter of what arrived since the last cycle, not a nag."""
def test_what_a_brief_left_alone_does_not_make_the_next_cycle_due(self):
from sisi import cycle
_contract(self)
self.git_init()
ids = [self.another(n) for n in range(12)]
self.assertIn("cycle is due (12 proposed", cycle.due_notice())
acts = [{"action": "reject", "learning": i, "why": "the %s importer was deleted in the last release" % i}
for i in ids[:3]]
self.assertEqual(self.apply(acts).returncode, 0)
self.assertEqual(len(cycle.proposed()), 9) # nine are still waiting, all of them in the next brief
self.assertNotIn("cycle is due", cycle.due_notice())
self.assertIn("L-0004", self.sisi("cycle").stdout)
# five new learnings make it due again; the leftovers ride along in that brief
for n in range(12, 17):
self.another(n)
self.assertIn("cycle is due (5 proposed", cycle.due_notice())
def test_the_ones_it_left_alone_come_due_again_after_two_weeks(self):
from sisi import cycle
_contract(self)
self.git_init()
ids = [self.another(n) for n in range(7)]
self.assertEqual(self.apply([{"action": "reject", "learning": ids[0],
"why": "the alpha importer was deleted in the last release"}]).returncode, 0)
self.assertNotIn("cycle is due", cycle.due_notice())
p = os.path.join(self.data, "cycles", "cycle-0001.json")
with open(p) as f:
rec = json.load(f)
rec["ts"] = "2000-01-01T00:00:00Z"
with open(p, "w") as f:
json.dump(rec, f)
self.assertIn("cycle is due (6 proposed", cycle.due_notice())
# a cycle that was reverted does not count as having run
rec["ts"] = L.now()
rec["reverted"] = L.now()
with open(p, "w") as f:
json.dump(rec, f)
self.assertIn("cycle is due (6 proposed", cycle.due_notice())