Choosing the approach is a checked step; three tiers for where knowledge lives; patterns
ci / tests (macos-latest, python 3.10) (push) Canceled after 0s
ci / tests (macos-latest, python 3.11) (push) Canceled after 0s
ci / tests (macos-latest, python 3.13) (push) Canceled after 0s
ci / tests (macos-latest, python 3.9) (push) Canceled after 0s
ci / tests (ubuntu-latest, python 3.10) (push) Canceled after 0s
ci / tests (ubuntu-latest, python 3.11) (push) Canceled after 0s
ci / tests (ubuntu-latest, python 3.13) (push) Canceled after 0s
ci / tests (macos-latest, python 3.10) (push) Canceled after 0s
ci / tests (macos-latest, python 3.11) (push) Canceled after 0s
ci / tests (macos-latest, python 3.13) (push) Canceled after 0s
ci / tests (macos-latest, python 3.9) (push) Canceled after 0s
ci / tests (ubuntu-latest, python 3.10) (push) Canceled after 0s
ci / tests (ubuntu-latest, python 3.11) (push) Canceled after 0s
ci / tests (ubuntu-latest, python 3.13) (push) Canceled after 0s
A new first rule and a required design section in the contract for sizeable work, validated structurally and enforced by the end-of-turn check. Lessons and statements are tiered core, user or project; core items are queued for the product (sisi promote). The owner's statements take effect at once and form the principles document. Every retro names the general pattern behind its incident; learning rounds group lessons under patterns. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
1 parent
ba84772acf
commit
ec91e526a6
32 files changed
+2484
-251
No files matched your search
@@ -0,0 +1,276 @@
|
||||
"""Live principles (`sisi learn`/`sisi oracle`), the contract design section, `sisi design`,
|
||||
the gate's design send-back, and request-time design delivery."""
|
||||
import json, os, subprocess, unittest
|
||||
from support import *
|
||||
|
||||
PRINCIPLES = [
|
||||
"drop into any user's environment and use what is already there",
|
||||
"mechanisms over good intentions: check it, do not just advise it",
|
||||
"never set up scheduled jobs or timers for me",
|
||||
]
|
||||
|
||||
|
||||
def good_design(principles=PRINCIPLES, **over):
|
||||
d = {
|
||||
"implies": ["The tool must work in an environment sisi did not choose, so discovery of what "
|
||||
"the host already provides comes before building any replacement for it."],
|
||||
"provided": [{"what": "git is already used for change measurement in this repository",
|
||||
"evidence": "command:git"},
|
||||
{"what": "the README documents the existing command surface to build on",
|
||||
"evidence": "file:README.md"}],
|
||||
"alternatives": [
|
||||
{"name": "shell out to each tool's command line",
|
||||
"cost": "one driver per tool, each with its own quoting and login handling",
|
||||
"risk": "breaks wherever a tool has no usable command line or changes its flags"},
|
||||
{"name": "build a new agent host of our own",
|
||||
"cost": "months of work duplicating sessions, auth and tool wiring from scratch",
|
||||
"risk": "nobody's existing setup carries over, so adoption starts from zero"},
|
||||
],
|
||||
"chosen": {"name": "use the host tool's own subagent mechanism",
|
||||
"why": "It drops into the user's existing environment instead of rebuilding what "
|
||||
"the host already provides, which is what the owner asked for."},
|
||||
"objections": [{"principle": p, "applicable": True,
|
||||
"objection": "You are rebuilding something the environment already gives me.",
|
||||
"answer": "The design calls the host mechanism and builds only the missing adapter."}
|
||||
if i < 2 else
|
||||
{"principle": p, "applicable": False,
|
||||
"reason": "Nothing in this design runs on a schedule; every step is triggered by use."}
|
||||
for i, p in enumerate(principles)],
|
||||
"challenge": {"by": "a subagent on a different model, briefed as the owner",
|
||||
"recorded_at": "2026-01-01T00:00:00Z",
|
||||
"objections": ["You never checked what the host already provides before designing drivers."],
|
||||
"changes": ["Made the host subagent mechanism the main path; command lines are the fallback."]},
|
||||
}
|
||||
d.update(over)
|
||||
return d
|
||||
|
||||
|
||||
class PrinciplesCase(SisiCase):
|
||||
def learn_all(self):
|
||||
for p in PRINCIPLES:
|
||||
r = self.sisi("learn", "--scope", "user", p)
|
||||
self.assertEqual(r.returncode, 0, r.stdout + r.stderr)
|
||||
|
||||
|
||||
class LivePrinciplesTests(PrinciplesCase):
|
||||
def test_learn_takes_effect_at_once_without_quarantine_wording(self):
|
||||
r = self.sisi("learn", "--scope", "user", PRINCIPLES[0])
|
||||
self.assertEqual(r.returncode, 0, r.stdout)
|
||||
self.assertNotIn("quarantin", (r.stdout + r.stderr).lower())
|
||||
out = self.sisi("oracle").stdout
|
||||
self.assertIn(PRINCIPLES[0], out)
|
||||
|
||||
def test_oracle_prints_one_principle_per_statement_with_quote_and_date(self):
|
||||
self.learn_all()
|
||||
out = self.sisi("oracle").stdout
|
||||
for p in PRINCIPLES:
|
||||
self.assertIn(p, out)
|
||||
self.assertIn('"%s"' % p, out)
|
||||
self.assertIn("Standing principles", out)
|
||||
|
||||
def test_quarantine_file_is_migrated_losslessly(self):
|
||||
os.makedirs(self.data, exist_ok=True)
|
||||
rec = {"ts": "2025-01-02T03:04:05Z", "cwd": self.proj, "tool": None, "session": None,
|
||||
"text": "always show options with a recommendation", "scope": "user"}
|
||||
with open(os.path.join(self.data, "learn-quarantine.jsonl"), "w") as f:
|
||||
f.write(json.dumps(rec) + "\n")
|
||||
out = self.sisi("oracle").stdout
|
||||
self.assertIn("always show options with a recommendation", out)
|
||||
self.assertIn("2025-01-02", out)
|
||||
self.assertTrue(os.path.exists(os.path.join(self.data, "learn.jsonl")))
|
||||
self.assertFalse(os.path.exists(os.path.join(self.data, "learn-quarantine.jsonl")))
|
||||
rows = [json.loads(l) for l in open(os.path.join(self.data, "learn.jsonl"))]
|
||||
self.assertEqual(rows[0]["text"], rec["text"])
|
||||
self.assertEqual(rows[0]["ts"], rec["ts"])
|
||||
|
||||
def test_learn_statement_may_name_sisi_itself(self):
|
||||
# the project folder is named proj in the fixture; use a folder named sisi
|
||||
d = os.path.join(self.tmp, "sisi")
|
||||
os.makedirs(d)
|
||||
subprocess.run(["git", "init", "-q"], cwd=d, check=True)
|
||||
r = self.sisi("learn", "--scope", "user",
|
||||
"sisi should anticipate what I need from what I already said", cwd=d)
|
||||
self.assertEqual(r.returncode, 0, r.stdout + r.stderr)
|
||||
|
||||
|
||||
class DesignValidationTests(PrinciplesCase):
|
||||
def errs(self, design):
|
||||
from sisi import design as D
|
||||
return D.validate_design({"goal": "g", "design": design}, cwd=REPO)
|
||||
|
||||
def test_good_design_passes(self):
|
||||
self.learn_all()
|
||||
self.assertEqual(self.errs(good_design()), [])
|
||||
|
||||
def test_missing_design_is_an_error(self):
|
||||
from sisi import design as D
|
||||
self.assertTrue(D.validate_design({"goal": "g"}, cwd=REPO))
|
||||
|
||||
def test_labelled_good_and_filler_sets(self):
|
||||
"""At least 12 good and 12 filler design sections: every good one passes, every filler fails."""
|
||||
self.learn_all()
|
||||
base = good_design()
|
||||
def variant(**kw):
|
||||
d = json.loads(json.dumps(base))
|
||||
d.update(kw)
|
||||
return d
|
||||
goods = [base]
|
||||
for i in range(11):
|
||||
d = json.loads(json.dumps(base))
|
||||
d["implies"] = ["Implication %d: the result must keep working when the host, the model "
|
||||
"and the project layout all change around it over time." % i]
|
||||
d["provided"] = [{"what": "python3 runs the whole tool and its checks already",
|
||||
"evidence": "command:python3"},
|
||||
{"what": "the licence file fixes the terms this ships under",
|
||||
"evidence": "file:LICENSE"}]
|
||||
d["alternatives"][0]["name"] = "bespoke driver number %d" % i
|
||||
d["challenge"]["by"] = "independent reviewer %d on a different model" % i
|
||||
goods.append(d)
|
||||
fillers = [
|
||||
variant(implies=["As requested."]),
|
||||
variant(implies=[]),
|
||||
variant(provided=[{"what": "existing tools", "evidence": "command:no-such-command-xyz"}]),
|
||||
variant(provided=["stuff that exists somewhere in general terms"]),
|
||||
variant(provided=[]),
|
||||
variant(alternatives=[base["alternatives"][0]]),
|
||||
variant(alternatives=[dict(base["alternatives"][0], name="use the host tool's own subagent mechanism"),
|
||||
base["alternatives"][1]]),
|
||||
variant(alternatives=[dict(base["alternatives"][0], cost="low", risk="low"),
|
||||
dict(base["alternatives"][1], cost="low", risk="low")]),
|
||||
variant(chosen={"name": "use the host tool's own subagent mechanism", "why": "best"}),
|
||||
variant(objections=[{"principle": PRINCIPLES[0], "applicable": True,
|
||||
"objection": "x", "answer": "y"}]),
|
||||
variant(objections=[dict(o, applicable=False, reason="n/a") if o.get("applicable") else o
|
||||
for o in base["objections"]]),
|
||||
variant(challenge={"by": "self", "recorded_at": "2026-01-01T00:00:00Z",
|
||||
"objections": ["none"], "changes": []}),
|
||||
variant(challenge={"by": "a subagent on a different model", "recorded_at": "2026-01-01T00:00:00Z",
|
||||
"objections": [], "changes": ["changed things in response to the review"]}),
|
||||
]
|
||||
good_pass = sum(1 for d in goods if not self.errs(d))
|
||||
filler_fail = sum(1 for d in fillers if self.errs(d))
|
||||
self.assertGreaterEqual(len(goods), 12)
|
||||
self.assertGreaterEqual(len(fillers), 12)
|
||||
self.assertEqual((good_pass, filler_fail), (len(goods), len(fillers)),
|
||||
"good %d/%d pass, filler %d/%d refused" % (good_pass, len(goods), filler_fail, len(fillers)))
|
||||
|
||||
|
||||
class DesignCommandTests(PrinciplesCase):
|
||||
def test_sisi_design_prints_principles_and_questions(self):
|
||||
self.learn_all()
|
||||
r = self.sisi("design")
|
||||
self.assertEqual(r.returncode, 0, r.stderr)
|
||||
for p in PRINCIPLES:
|
||||
self.assertIn(p, r.stdout)
|
||||
for key in ("implies", "provided", "alternatives", "chosen", "objections", "challenge"):
|
||||
self.assertIn(key, r.stdout)
|
||||
|
||||
def test_contract_init_prints_principles_and_design_skeleton(self):
|
||||
self.learn_all()
|
||||
r = self.sisi("contract", "init", "--goal", "build the orchestrator")
|
||||
self.assertEqual(r.returncode, 0, r.stdout)
|
||||
self.assertIn(PRINCIPLES[0], r.stdout)
|
||||
c = json.load(open(os.path.join(self.proj, ".sisi", "contract.json")))
|
||||
self.assertIn("design", c)
|
||||
for key in ("implies", "provided", "alternatives", "chosen", "objections", "challenge"):
|
||||
self.assertIn(key, c["design"])
|
||||
|
||||
|
||||
class DesignGateTests(PrinciplesCase):
|
||||
def gate(self, payload):
|
||||
return self.sisi("gate", stdin=json.dumps(payload))
|
||||
|
||||
def large_contract_project(self, design=None):
|
||||
self.git_init()
|
||||
c = contract([check("a", "true")])
|
||||
if design is not None:
|
||||
c["design"] = design
|
||||
self.write_contract(c)
|
||||
with open(os.path.join(self.proj, "big.txt"), "w") as f:
|
||||
f.write("line\n" * 80)
|
||||
return {"session_id": "gate-design-1", "cwd": self.proj, "stop_hook_active": False}
|
||||
|
||||
def test_large_change_without_design_is_sent_back_then_never_traps(self):
|
||||
self.learn_all()
|
||||
payload = self.large_contract_project()
|
||||
msgs = []
|
||||
for _ in range(5):
|
||||
r = self.gate(payload)
|
||||
out = r.stdout.strip()
|
||||
if not out:
|
||||
break
|
||||
d = json.loads(out)
|
||||
msgs.append(d)
|
||||
if d.get("decision") != "block":
|
||||
break
|
||||
self.assertTrue(any("design" in (m.get("reason") or "") for m in msgs), msgs)
|
||||
# never traps: within the send-back budget the turn is let through
|
||||
self.assertLessEqual(len([m for m in msgs if m.get("decision") == "block"]), 3)
|
||||
|
||||
def test_large_change_with_good_design_is_not_sent_back_for_design(self):
|
||||
self.learn_all()
|
||||
payload = self.large_contract_project(design=good_design())
|
||||
r = self.gate(payload)
|
||||
self.assertNotIn("design section is missing", r.stdout)
|
||||
|
||||
def test_small_change_needs_no_design(self):
|
||||
self.git_init()
|
||||
self.write_contract(contract([check("a", "true")]))
|
||||
with open(os.path.join(self.proj, "small.txt"), "w") as f:
|
||||
f.write("one line\n")
|
||||
r = self.gate({"session_id": "gate-design-small", "cwd": self.proj})
|
||||
self.assertNotIn("design", r.stdout)
|
||||
|
||||
|
||||
class PromptDesignTests(PrinciplesCase):
|
||||
def test_design_work_gets_principles_and_instruction(self):
|
||||
self.learn_all()
|
||||
from sisi import prompt as P
|
||||
ctx = P.build_context("Build an automatic orchestrator that delegates work to other agents "
|
||||
"across the tools installed here, with routing and judged outcomes")
|
||||
self.assertIn(PRINCIPLES[0], ctx)
|
||||
self.assertIn("design", ctx.lower())
|
||||
self.assertLessEqual(len(ctx), P.MAX_CHARS)
|
||||
|
||||
def test_questions_and_small_edits_get_no_design_block(self):
|
||||
self.learn_all()
|
||||
from sisi import prompt as P
|
||||
for q in ("Should the orchestrator use subagents or command lines?",
|
||||
"rename the helper that formats the orchestrator headings in the docs",
|
||||
"fix the typo in the orchestrator help text on the second line"):
|
||||
self.assertNotIn(PRINCIPLES[0], P.build_context(q), q)
|
||||
|
||||
def test_labelled_design_requests(self):
|
||||
self.learn_all()
|
||||
from sisi import prompt as P
|
||||
should = [
|
||||
"Build an automatic orchestrator that delegates work to other agents across tools",
|
||||
"Design and implement a new storage layer for session records with migration",
|
||||
"Create a command that discovers installed agent tools and routes work between them",
|
||||
"Implement a plugin system so other tools can add their own checks to the gate",
|
||||
]
|
||||
should_not = [
|
||||
"Why does the orchestrator choose that worker for this kind of work?",
|
||||
"rename the local variable in the routing helper to something clearer",
|
||||
"fix the off-by-one in the pagination control of the list view",
|
||||
"What does the design section of a contract actually require in full?",
|
||||
]
|
||||
hits = sum(1 for t in should if "design section" in P.build_context(t))
|
||||
false = sum(1 for t in should_not if "design section" in P.build_context(t))
|
||||
self.assertEqual((hits, false), (len(should), 0),
|
||||
"design hits %d/%d, false %d/%d" % (hits, len(should), false, len(should_not)))
|
||||
|
||||
|
||||
class RuleDesignTests(SisiCase):
|
||||
def test_first_rule_is_choose_the_approach_with_real_enforcement(self):
|
||||
r = self.sisi("rule", "1")
|
||||
self.assertEqual(r.returncode, 0, r.stderr)
|
||||
self.assertIn("choose-the-approach", r.stdout)
|
||||
self.assertIn("Why:", r.stdout)
|
||||
from sisi import rulecmd
|
||||
self.assertIn("design", rulecmd.enforcement_for("choose-the-approach"))
|
||||
self.assertNotIn("not enforced", rulecmd.enforcement_for("choose-the-approach"))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -56,8 +56,23 @@ class ShortCase(LibCase):
|
||||
have = {e.get("lesson") for e in notes if isinstance(e, dict) and e.get("action") == "set-scope"}
|
||||
for e in list(notes):
|
||||
if isinstance(e, dict) and isinstance(e.get("lesson"), int) and e["lesson"] not in have:
|
||||
notes.append({"lesson": e["lesson"], "action": "set-scope", "scope": "everywhere"})
|
||||
notes.append({"lesson": e["lesson"], "action": "set-scope", "scope": "core"})
|
||||
have.add(e["lesson"])
|
||||
# every active lesson lacking a pattern needs a set-pattern too
|
||||
try:
|
||||
_con = retro.connect()
|
||||
try:
|
||||
_prows = [dict(r) for r in _con.execute(
|
||||
"SELECT id, pattern_id, scope FROM lessons WHERE status IN ('open','applied')")]
|
||||
finally:
|
||||
_con.close()
|
||||
_have_p = {e.get("lesson") for e in notes if isinstance(e, dict) and e.get("action") == "set-pattern"}
|
||||
_exempt = {e.get("lesson") for e in notes if isinstance(e, dict) and e.get("action") in ("retire", "withdraw", "merge")}
|
||||
for r in _prows:
|
||||
if not r.get("pattern_id") and r["id"] not in _have_p and r["id"] not in _exempt and r.get("scope") != "project":
|
||||
notes.append({"lesson": r["id"], "action": "set-pattern", "pattern": "Reach for the familiar tool instead of the check that fits the claim"})
|
||||
except Exception:
|
||||
pass
|
||||
doc["notes"] = notes
|
||||
doc.update(parts)
|
||||
# A cycle file must also answer for every document the brief lists for whole-document
|
||||
|
||||
@@ -53,7 +53,7 @@ class DocCase(LibCase):
|
||||
f = dict(aim="verified", change_kind="recipe", target="parser-or-codec",
|
||||
moment="the parser accepted a truncated file in the nightly job",
|
||||
cause="no truncated-input case existed", change=change, when=WHEN,
|
||||
scope="everywhere", short="Seed the corpus from golden files.", topic="parsing")
|
||||
scope="core", short="Seed the corpus from golden files.", topic="parsing", pattern="Reach for the familiar tool instead of the check that fits the claim")
|
||||
f.update(kw)
|
||||
con = retro.connect()
|
||||
try:
|
||||
|
||||
+20
-1
@@ -436,7 +436,26 @@ class GateGrowthTests(GateBase):
|
||||
def test_contract_ends_it(self):
|
||||
self.grow("a.txt", 100)
|
||||
self.assertEqual(self.call()[0], "block")
|
||||
self.write_contract(contract([check("c", "true")]))
|
||||
c = contract([check("c", "true")])
|
||||
c["design"] = {
|
||||
"implies": ["A change this size needs its approach recorded so the next agent can "
|
||||
"see why it went this way and what was ruled out."],
|
||||
"provided": [{"what": "git already measures the change in this repository",
|
||||
"evidence": "command:git"}],
|
||||
"alternatives": [
|
||||
{"name": "keep blocking on growth alone", "cost": "no new code to write at all",
|
||||
"risk": "a contract can be gamed with checks that prove nothing real"},
|
||||
{"name": "ask the human to approve large changes", "cost": "one prompt per change",
|
||||
"risk": "the human becomes the bottleneck for routine sizeable work"}],
|
||||
"chosen": {"name": "contract with a checked design section",
|
||||
"why": "It is the option the owner would pick: the approach is recorded "
|
||||
"and checked mechanically instead of depending on goodwill."},
|
||||
"objections": [],
|
||||
"challenge": {"by": "a subagent on a different model",
|
||||
"recorded_at": "2026-01-01T00:00:00Z",
|
||||
"objections": ["The design section could become ceremony filled with filler text."],
|
||||
"changes": ["Required evidence that named existing things actually exist."]}}
|
||||
self.write_contract(c)
|
||||
self.assertEqual(self.call()[0], "allow")
|
||||
|
||||
def test_waiver_covers_tree_at_that_moment_only(self):
|
||||
|
||||
+20
-13
@@ -61,7 +61,7 @@ class LearningCase(LibCase):
|
||||
con = retro.connect()
|
||||
try:
|
||||
rows = [dict(r) for r in con.execute(
|
||||
"SELECT id, short, topic FROM lessons WHERE status IN ('open','applied')")]
|
||||
"SELECT id, short, topic, pattern_id, scope FROM lessons WHERE status IN ('open','applied')")]
|
||||
finally:
|
||||
con.close()
|
||||
notes = list(doc.get("notes") or [])
|
||||
@@ -70,9 +70,12 @@ class LearningCase(LibCase):
|
||||
exempt = {e.get("lesson") for e in notes if isinstance(e, dict)
|
||||
and e.get("action") in ("retire", "withdraw", "merge")}
|
||||
extra = []
|
||||
patterned = {e.get("lesson") for e in notes if isinstance(e, dict) and e.get("action") == "set-pattern"}
|
||||
for r in rows:
|
||||
if r["id"] not in scoped and r["id"] not in exempt:
|
||||
extra.append({"lesson": r["id"], "action": "set-scope", "scope": "everywhere"})
|
||||
extra.append({"lesson": r["id"], "action": "set-scope", "scope": "core"})
|
||||
if not r.get("pattern_id") and r["id"] not in patterned and r["id"] not in exempt and r.get("scope") != "project":
|
||||
extra.append({"lesson": r["id"], "action": "set-pattern", "pattern": "Reach for the familiar tool instead of the check that fits the claim"})
|
||||
if r["id"] in covered or r["id"] in exempt:
|
||||
continue
|
||||
if (r.get("short") or "").strip() and (r.get("topic") or "").strip():
|
||||
@@ -493,9 +496,10 @@ class CycleApplyTests(LearningCase):
|
||||
b = self.mk(change="Session two lesson about widget caching", moment="s2 wait at step 2")
|
||||
base = cycle.base_version() # both sessions read the same brief
|
||||
_ss = lambda lid: {"lesson": lid, "action": "set-short", "short": "Use a readiness probe, not a sleep.", "topic": "testing"}
|
||||
_sc = lambda lid: {"lesson": lid, "action": "set-scope", "scope": "everywhere"}
|
||||
doc1 = {"version": 1, "base": base, "summary": "one", "notes": [{"lesson": a, "action": "keep"}, _ss(a), _ss(b), _sc(a), _sc(b)]}
|
||||
doc2 = {"version": 1, "base": base, "summary": "two", "notes": [{"lesson": b, "action": "keep"}, _ss(a), _ss(b), _sc(a), _sc(b)]}
|
||||
_sc = lambda lid: {"lesson": lid, "action": "set-scope", "scope": "core"}
|
||||
_sp = lambda lid: {"lesson": lid, "action": "set-pattern", "pattern": "Reach for the familiar tool instead of the check that fits the claim"}
|
||||
doc1 = {"version": 1, "base": base, "summary": "one", "notes": [{"lesson": a, "action": "keep"}, _ss(a), _ss(b), _sc(a), _sc(b), _sp(a), _sp(b)]}
|
||||
doc2 = {"version": 1, "base": base, "summary": "two", "notes": [{"lesson": b, "action": "keep"}, _ss(a), _ss(b), _sc(a), _sc(b), _sp(a), _sp(b)]}
|
||||
paths_ = []
|
||||
for i, d in enumerate((doc1, doc2)):
|
||||
p = os.path.join(self.tmp, "two-%d.json" % i)
|
||||
@@ -780,7 +784,7 @@ class MatchingCorpusTests(LearningCase):
|
||||
r = self.sisi("retro", "--new", "--scope", "everywhere", "--aim", "verified",
|
||||
"--moment", "The CSV importer test passed but 'python3 import.py big.csv' crashed on a quoted comma in row 4011",
|
||||
"--cause", "the importer was only tested with three hand-written rows",
|
||||
"--change-kind", "rule", "--when", CSV_WHEN,
|
||||
"--change-kind", "rule", "--when", CSV_WHEN, "--pattern", "Reach for the familiar tool instead of the check that fits the claim",
|
||||
"--change", "For any CSV importer, run a property test that round-trips generated rows containing quotes, commas and newlines before saying it works")
|
||||
self.assertEqual(r.returncode, 0, r.stdout)
|
||||
self.assertIn("lesson #", r.stdout)
|
||||
@@ -849,13 +853,13 @@ class MatchingCorpusTests(LearningCase):
|
||||
first = self.sisi("retro", "--new", "--scope", "everywhere", "--aim", "verified",
|
||||
"--moment", "the parser server waited 90 seconds in step 4 of the nightly job",
|
||||
"--cause", "no readiness probe existed before the browser step",
|
||||
"--change-kind", "rule", "--when", PARSER_WHEN, "--change", PARSER_CHANGE)
|
||||
"--change-kind", "rule", "--when", PARSER_WHEN, "--pattern", "Reach for the familiar tool instead of the check that fits the claim", "--change", PARSER_CHANGE)
|
||||
self.assertEqual(first.returncode, 0, first.stdout)
|
||||
lid = int(first.stdout.split("lesson #")[1].split(",")[0])
|
||||
dup = self.sisi("retro", "--scope", "everywhere", "--aim", "verified",
|
||||
"--moment", "again the parser server waited 90 seconds in step 9 of the nightly job",
|
||||
"--cause", "still no readiness probe before the browser step at all",
|
||||
"--change-kind", "rule", "--when", PARSER_WHEN,
|
||||
"--change-kind", "rule", "--when", PARSER_WHEN, "--pattern", "Reach for the familiar tool instead of the check that fits the claim",
|
||||
"--change", "Prefer a readiness probe over a fixed sleep when waiting for parser servers")
|
||||
self.assertEqual(dup.returncode, 4, dup.stdout)
|
||||
self.assertIn("sighting was kept", dup.stdout)
|
||||
@@ -866,7 +870,7 @@ class MatchingCorpusTests(LearningCase):
|
||||
as_new = self.sisi("retro", "--new", "--scope", "everywhere", "--aim", "verified",
|
||||
"--moment", "again the parser server waited 90 seconds in step 9 of the nightly job",
|
||||
"--cause", "still no readiness probe before the browser step at all",
|
||||
"--change-kind", "rule", "--when", PARSER_WHEN,
|
||||
"--change-kind", "rule", "--when", PARSER_WHEN, "--pattern", "Reach for the familiar tool instead of the check that fits the claim",
|
||||
"--change", "Prefer a readiness probe over a fixed sleep when waiting for parser servers")
|
||||
self.assertEqual(as_new.returncode, 0, as_new.stdout) # kept apart, but the sighting is not lost
|
||||
con = retro.connect()
|
||||
@@ -990,7 +994,7 @@ class ImproveFromUseTests(LearningCase):
|
||||
a = self.sisi("retro", "--new", "--scope", "everywhere", "--aim", "verified",
|
||||
"--moment", "The CSV importer test passed but 'python3 import.py big.csv' crashed on a quoted comma in row 4011",
|
||||
"--cause", "the importer was only tested with three hand-written rows",
|
||||
"--change-kind", "rule", "--when", CSV_WHEN,
|
||||
"--change-kind", "rule", "--when", CSV_WHEN, "--pattern", "Reach for the familiar tool instead of the check that fits the claim",
|
||||
"--change", "For any CSV importer, run a property test that round-trips generated rows containing quotes, commas and newlines before saying it works",
|
||||
env={"SISI_SESSION_ID": "session-A"})
|
||||
self.assertEqual(a.returncode, 0, a.stdout)
|
||||
@@ -1070,7 +1074,8 @@ class CycleGapTests(LearningCase):
|
||||
doc = self.cycle_doc(notes=[{"lesson": lid, "action": "keep"}])
|
||||
# cycle_doc recomputes base; rebuild with the original base
|
||||
d = {"version": 1, "base": base, "summary": "x", "notes": [{"lesson": lid, "action": "keep"},
|
||||
{"lesson": lid, "action": "set-scope", "scope": "everywhere"},
|
||||
{"lesson": lid, "action": "set-scope", "scope": "core"},
|
||||
{"lesson": lid, "action": "set-pattern", "pattern": "Reach for the familiar tool instead of the check that fits the claim"},
|
||||
{"lesson": lid, "action": "set-short", "short": "Use a readiness probe, not a sleep.", "topic": "testing"}]}
|
||||
p = os.path.join(self.tmp, "g2.json")
|
||||
with open(p, "w") as f:
|
||||
@@ -1096,7 +1101,8 @@ class CycleGapTests(LearningCase):
|
||||
base = cycle.base_version()
|
||||
self.mk(change="Brand new parser lesson arriving mid cycle", moment="new wait at step 5")
|
||||
d = {"version": 1, "base": base, "summary": "x", "notes": [{"lesson": lid, "action": "keep"},
|
||||
{"lesson": lid, "action": "set-scope", "scope": "everywhere"},
|
||||
{"lesson": lid, "action": "set-scope", "scope": "core"},
|
||||
{"lesson": lid, "action": "set-pattern", "pattern": "Reach for the familiar tool instead of the check that fits the claim"},
|
||||
{"lesson": lid, "action": "set-short", "short": "Use a readiness probe, not a sleep.", "topic": "testing"}]}
|
||||
p = os.path.join(self.tmp, "g3.json")
|
||||
with open(p, "w") as f:
|
||||
@@ -1230,7 +1236,8 @@ class CycleGapTests(LearningCase):
|
||||
|
||||
def test_gap16_rule_numbers_map_to_ids(self):
|
||||
out = cycle.brief_text()
|
||||
self.assertIn("1. know-done", out)
|
||||
self.assertIn("1. choose-the-approach", out)
|
||||
self.assertIn("2. know-done", out)
|
||||
self.assertIn("rule 5", out)
|
||||
|
||||
def test_gap17_enforced_help_fields_and_examples(self):
|
||||
|
||||
@@ -0,0 +1,167 @@
|
||||
"""Patterns: `sisi retro --pattern`, `sisi retro patterns`, the cycle's set-pattern action,
|
||||
and patterns-first digest/improve."""
|
||||
import json, os, unittest
|
||||
from support import *
|
||||
from sisi import retro
|
||||
|
||||
WHEN = "csv, tsv, spreadsheet, tabular data, import, export, parse, delimited file"
|
||||
PATTERN = "Build the obvious thing instead of using what the environment already provides"
|
||||
|
||||
|
||||
def retro_args(**kw):
|
||||
f = dict(aim="verified", moment="the export broke on a quoted field at step 2 of the run",
|
||||
cause="rows were joined by hand instead of with the writer the project already had",
|
||||
change_kind="rule", change="Write delimited files with a quoting writer so fields survive",
|
||||
when=WHEN, scope="core", pattern=PATTERN,
|
||||
short="Use a quoting writer for delimited exports.", topic="data files")
|
||||
f.update(kw)
|
||||
out = []
|
||||
for k in ("aim", "moment", "cause", "change_kind", "change", "when", "scope", "short", "topic", "pattern"):
|
||||
if f.get(k) is not None:
|
||||
out += ["--" + k.replace("_", "-"), str(f[k])]
|
||||
if f.get("pattern_id") is not None:
|
||||
out += ["--pattern-id", str(f["pattern_id"])]
|
||||
return out
|
||||
|
||||
|
||||
class RetroPatternTests(SisiCase):
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.git_init()
|
||||
|
||||
def test_pattern_is_required_for_a_new_lesson(self):
|
||||
r = self.sisi("retro", *retro_args(pattern=None))
|
||||
self.assertNotEqual(r.returncode, 0, r.stdout)
|
||||
self.assertIn("pattern", (r.stdout + r.stderr).lower())
|
||||
|
||||
def test_pattern_is_stored_and_reused_not_duplicated(self):
|
||||
r = self.sisi("retro", *retro_args())
|
||||
self.assertEqual(r.returncode, 0, r.stdout)
|
||||
r = self.sisi("retro", "--new", *retro_args(
|
||||
moment="another export broke on an embedded newline at step 4 of the run",
|
||||
change="Write delimited files with a quoting writer so newlines survive"))
|
||||
self.assertEqual(r.returncode, 0, r.stdout)
|
||||
con = retro.connect()
|
||||
try:
|
||||
pats = retro.patterns(con)
|
||||
self.assertEqual(len(pats), 1, pats)
|
||||
self.assertEqual(pats[0]["statement"], PATTERN)
|
||||
ids = [row[0] for row in con.execute("SELECT pattern_id FROM lessons ORDER BY id")]
|
||||
self.assertEqual(ids, [pats[0]["id"], pats[0]["id"]])
|
||||
finally:
|
||||
con.close()
|
||||
|
||||
def test_retro_patterns_lists_them_and_pattern_id_selects(self):
|
||||
self.assertEqual(self.sisi("retro", *retro_args()).returncode, 0)
|
||||
out = self.sisi("retro", "patterns").stdout
|
||||
self.assertIn(PATTERN, out)
|
||||
r = self.sisi("retro", "--new", *retro_args(
|
||||
pattern=None, pattern_id=1,
|
||||
moment="a third export broke on a delimiter in a name at step 1 of the run",
|
||||
change="Write delimited files with a quoting writer so delimiters survive"))
|
||||
self.assertEqual(r.returncode, 0, r.stdout)
|
||||
con = retro.connect()
|
||||
try:
|
||||
self.assertEqual(len(retro.patterns(con)), 1)
|
||||
finally:
|
||||
con.close()
|
||||
|
||||
def test_pattern_naming_the_project_or_restating_the_change_is_refused(self):
|
||||
r = self.sisi("retro", *retro_args(pattern="proj export rows are joined by hand in this repo"))
|
||||
self.assertNotEqual(r.returncode, 0, r.stdout)
|
||||
r = self.sisi("retro", *retro_args(pattern="Write delimited files with a quoting writer so fields survive"))
|
||||
self.assertNotEqual(r.returncode, 0, r.stdout)
|
||||
|
||||
|
||||
class CyclePatternTests(SisiCase):
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.git_init()
|
||||
|
||||
def lesson_without_pattern(self):
|
||||
con = retro.connect()
|
||||
try:
|
||||
lid = retro.new_lesson(con, dict(
|
||||
aim="verified", change_kind="rule", target=None,
|
||||
moment="the export broke on a quoted field at step 2 of the run",
|
||||
cause="rows were joined by hand instead of with a quoting writer",
|
||||
change="Write delimited files with a quoting writer so fields survive",
|
||||
when=WHEN, short="Use a quoting writer for delimited exports.", topic="data files",
|
||||
scope="core"), self.proj, None)
|
||||
con.commit()
|
||||
return lid
|
||||
finally:
|
||||
con.close()
|
||||
|
||||
def test_cycle_brief_lists_patterns_and_check_requires_set_pattern(self):
|
||||
lid = self.lesson_without_pattern()
|
||||
brief = self.sisi("cycle", "--now").stdout
|
||||
self.assertIn("pattern", brief.lower())
|
||||
from sisi import cycle
|
||||
doc = {"version": 1, "base": cycle.base_version(), "summary": "x",
|
||||
"notes": [{"lesson": lid, "action": "keep"}]}
|
||||
p = os.path.join(self.tmp, "cyc.json")
|
||||
with open(p, "w") as f:
|
||||
json.dump(doc, f)
|
||||
r = self.sisi("cycle", "check", p)
|
||||
self.assertEqual(r.returncode, 1, r.stdout)
|
||||
self.assertIn("set-pattern", r.stdout)
|
||||
doc["notes"].append({"lesson": lid, "action": "set-pattern", "pattern": PATTERN})
|
||||
with open(p, "w") as f:
|
||||
json.dump(doc, f)
|
||||
r = self.sisi("cycle", "check", p)
|
||||
self.assertEqual(r.returncode, 0, r.stdout + r.stderr)
|
||||
r = self.sisi("cycle", "apply", p)
|
||||
self.assertEqual(r.returncode, 0, r.stdout + r.stderr)
|
||||
con = retro.connect()
|
||||
try:
|
||||
self.assertEqual(retro.patterns(con)[0]["statement"], PATTERN)
|
||||
finally:
|
||||
con.close()
|
||||
|
||||
def test_pattern_merge_keeps_one(self):
|
||||
con = retro.connect()
|
||||
try:
|
||||
a = retro.get_or_create_pattern(con, PATTERN)
|
||||
b = retro.get_or_create_pattern(con, "Rebuild what already exists instead of calling it")
|
||||
con.commit()
|
||||
finally:
|
||||
con.close()
|
||||
lid = self.lesson_without_pattern()
|
||||
from sisi import cycle
|
||||
doc = {"version": 1, "base": cycle.base_version(), "summary": "merge patterns",
|
||||
"notes": [{"lesson": lid, "action": "set-pattern", "pattern_id": b}],
|
||||
"patterns": [{"pattern": b, "action": "merge", "into": a}]}
|
||||
p = os.path.join(self.tmp, "cyc.json")
|
||||
with open(p, "w") as f:
|
||||
json.dump(doc, f)
|
||||
r = self.sisi("cycle", "apply", p)
|
||||
self.assertEqual(r.returncode, 0, r.stdout + r.stderr)
|
||||
con = retro.connect()
|
||||
try:
|
||||
pats = retro.patterns(con)
|
||||
self.assertEqual([x["id"] for x in pats], [a])
|
||||
self.assertEqual(con.execute("SELECT pattern_id FROM lessons WHERE id=?", (lid,)).fetchone()[0], a)
|
||||
finally:
|
||||
con.close()
|
||||
|
||||
|
||||
class PatternsFirstTests(SisiCase):
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.git_init()
|
||||
self.assertEqual(self.sisi("retro", *retro_args()).returncode, 0)
|
||||
|
||||
def test_digest_shows_patterns_first(self):
|
||||
out = self.sisi("lessons", "digest").stdout
|
||||
self.assertIn("## Patterns", out)
|
||||
self.assertLess(out.index("## Patterns"), out.index("## In sisi itself"))
|
||||
self.assertIn(PATTERN, out)
|
||||
|
||||
def test_improve_shows_patterns(self):
|
||||
out = self.sisi("improve").stdout
|
||||
self.assertIn(PATTERN, out)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -554,7 +554,7 @@ class ExportImportTests(PersonalCase):
|
||||
self.ok("learn", "--scope", "everywhere", "never", "ask", "twice")
|
||||
self.ok("retro", "--scope", "everywhere", "--aim", "verified", "--moment", "ran `pytest -q` and saw 3 passed but the new test had never failed",
|
||||
"--cause", "the test was written after the code", "--change-kind", "rule",
|
||||
"--when", "tests, pytest, failing first, regression, test quality, red green",
|
||||
"--when", "tests, pytest, failing first, regression, test quality, red green", "--pattern", "Reach for the familiar tool instead of the check that fits the claim",
|
||||
"--change", "write the failing test first and show it fail with `pytest -k new`")
|
||||
os.makedirs(os.path.join(self.state, "sessions"))
|
||||
open(os.path.join(self.state, "sessions", "s1.json"), "w").write('{"a": 1}')
|
||||
@@ -590,7 +590,7 @@ class ExportImportTests(PersonalCase):
|
||||
def test_import_sets_existing_data_aside_and_rebuilds_db_from_the_dump(self):
|
||||
self.ok("retro", "--scope", "everywhere", "--aim", "verified", "--moment", "ran `pytest -q` and saw 3 passed but the new test had never failed",
|
||||
"--cause", "the test was written after the code", "--change-kind", "rule",
|
||||
"--when", "tests, pytest, failing first, regression, test quality, red green",
|
||||
"--when", "tests, pytest, failing first, regression, test quality, red green", "--pattern", "Reach for the familiar tool instead of the check that fits the claim",
|
||||
"--change", "write the failing test first and show it fail with `pytest -k new`")
|
||||
arc = os.path.join(self.tmp, "out.tar.gz")
|
||||
self.ok("export", arc)
|
||||
@@ -634,7 +634,7 @@ def LessonRows():
|
||||
class LessonDumpTests(PersonalCase):
|
||||
RETRO = ["--scope", "everywhere", "--aim", "verified", "--moment", "ran `pytest -q` and saw 3 passed but the new test had never failed",
|
||||
"--cause", "the test was written after the code", "--change-kind", "rule",
|
||||
"--when", "tests, pytest, failing first, regression, test quality, red green",
|
||||
"--when", "tests, pytest, failing first, regression, test quality, red green", "--pattern", "Reach for the familiar tool instead of the check that fits the claim",
|
||||
"--change", "write the failing test first and show it fail with `pytest -k new`"]
|
||||
|
||||
def test_dump_is_committed_sorted_and_the_database_is_not(self):
|
||||
@@ -661,8 +661,8 @@ class LessonDumpTests(PersonalCase):
|
||||
def test_learn_and_note_are_personal_and_committed(self):
|
||||
self.ok("learn", "--scope", "everywhere", "Always", "use", "options")
|
||||
self.assertIn("learn: Always use options", self.git_log()[0])
|
||||
self.assertIn("learn-quarantine.jsonl", pdata.git("ls-files").stdout)
|
||||
self.assertFalse(os.path.exists(os.path.join(self.state, "learn-quarantine.jsonl")))
|
||||
self.assertIn("learn.jsonl", pdata.git("ls-files").stdout)
|
||||
self.assertFalse(os.path.exists(os.path.join(self.state, "learn.jsonl")))
|
||||
self.assertIn("oracle", self.ok("oracle").stdout.lower())
|
||||
|
||||
|
||||
|
||||
+3
-2
@@ -10,7 +10,7 @@ GOOD = dict(aim="verified",
|
||||
change_kind="recipe",
|
||||
change="Add the fuzz verifier to the Checks of the parser-or-codec recipe so parser work picks it by default",
|
||||
when="parser, fuzzing, codec, hostile input, generated input, parsing",
|
||||
scope="everywhere", target="parser-or-codec")
|
||||
scope="everywhere", target="parser-or-codec", pattern="Reach for the familiar tool instead of the check that fits the claim")
|
||||
|
||||
|
||||
def argv(f):
|
||||
@@ -266,6 +266,7 @@ class SimilarityAndSameAsTests(RetroCase):
|
||||
def test_dissimilar_lesson_accepted_directly(self):
|
||||
self.retro()
|
||||
other = dict(aim="speed", change_kind="tool", target="", scope="everywhere",
|
||||
pattern="Reach for the familiar tool instead of the check that fits the claim",
|
||||
moment="the screenshot comparison in `web-ui` waited 90 seconds on a dev server that never started",
|
||||
cause="no readiness probe before the browser step",
|
||||
when="browser, screenshot, dev server, port waiting, ui checks, startup",
|
||||
@@ -539,7 +540,7 @@ class GateRetroTests(RetroCase):
|
||||
self.work()
|
||||
a, msg = self.gate()
|
||||
self.assertEqual(a, "block")
|
||||
self.assertIn("sisi retro --aim", msg)
|
||||
self.assertIn("sisi retro --scope", msg)
|
||||
self.assertIn("--change-kind", msg)
|
||||
self.assertIn("how, not whether", msg)
|
||||
self.do_retro()
|
||||
|
||||
+1
-1
@@ -31,7 +31,7 @@ class RuleTableTests(SisiCase):
|
||||
|
||||
class RuleDetailTests(SisiCase):
|
||||
def test_rule_by_number_and_by_id(self):
|
||||
by_num = self.sisi("rule", "5")
|
||||
by_num = self.sisi("rule", "6")
|
||||
by_id = self.sisi("rule", "decide-dont-ask")
|
||||
self.assertEqual(by_num.returncode, 0, by_num.stderr)
|
||||
self.assertEqual(by_id.returncode, 0, by_id.stderr)
|
||||
|
||||
+5
-3
@@ -9,7 +9,8 @@ def retro_args(**kw):
|
||||
cause="rows were joined by hand in acme-widgets instead of with a quoting writer",
|
||||
change_kind="rule",
|
||||
change="Write delimited files with a quoting writer so embedded newlines survive",
|
||||
when=WHEN, short="Use a quoting writer for delimited exports.", topic="data files")
|
||||
when=WHEN, short="Use a quoting writer for delimited exports.", topic="data files",
|
||||
pattern="Build the obvious thing instead of using what the environment already provides")
|
||||
f.update(kw)
|
||||
out = []
|
||||
for k, v in f.items():
|
||||
@@ -93,7 +94,7 @@ class RetroScopeTests(ScopeCase):
|
||||
def test_missing_scope_refused_with_explanation(self):
|
||||
r = self.sisi("retro", *retro_args())
|
||||
self.assertEqual(r.returncode, 2, r.stdout)
|
||||
self.assertIn("everywhere", r.stdout); self.assertIn("project", r.stdout)
|
||||
self.assertIn("core", r.stdout); self.assertIn("user", r.stdout); self.assertIn("project", r.stdout)
|
||||
self.assertIn("general terms", r.stdout)
|
||||
|
||||
def test_everywhere_naming_project_refused(self):
|
||||
@@ -182,7 +183,8 @@ class StaleReadingTests(ScopeCase):
|
||||
self.assertEqual(st["status"], "applied") # retirement deferred while the round is open
|
||||
doc = {"version": 1, "base": base, "summary": "keep",
|
||||
"notes": [{"lesson": lid, "action": "set-short", "short": "Seed fuzz corpus from golden files.", "topic": "testing"},
|
||||
{"lesson": lid, "action": "set-scope", "scope": "everywhere"}]}
|
||||
{"lesson": lid, "action": "set-pattern", "pattern": "Reach for the familiar tool instead of the check that fits the claim"},
|
||||
{"lesson": lid, "action": "set-scope", "scope": "core"}]}
|
||||
p = os.path.join(self.tmp, "cyc.json")
|
||||
with open(p, "w") as f: json.dump(doc, f)
|
||||
r = self.sisi("cycle", "check", p)
|
||||
|
||||
@@ -82,7 +82,7 @@ class StoreTests(SisiCase):
|
||||
return [json.loads(l) for l in f]
|
||||
|
||||
def test_note_propose_learn_append_with_context(self):
|
||||
for cmd, fn in (("note", "notes.jsonl"), ("propose", "proposals.jsonl"), ("learn", "learn-quarantine.jsonl")):
|
||||
for cmd, fn in (("note", "notes.jsonl"), ("propose", "proposals.jsonl"), ("learn", "learn.jsonl")):
|
||||
extra = ["--scope", "everywhere"] if cmd == "learn" else []
|
||||
self.assertEqual(self.sisi(cmd, *(extra + ["first", "entry"]), env={"SISI_TOOL": "codex", "SISI_SESSION_ID": "s9"}).returncode, 0)
|
||||
self.sisi(cmd, *(extra + ["second"]))
|
||||
|
||||
@@ -0,0 +1,207 @@
|
||||
"""Three tiers (core, user, project): round-trips, migration of `everywhere`, the sisi-name
|
||||
exemption, promote on a developer install, export, and exact cycle revert with tiers."""
|
||||
import json, os, shutil, subprocess, unittest
|
||||
from support import *
|
||||
from sisi import retro, scope, store
|
||||
|
||||
WHEN = "csv, tsv, spreadsheet, tabular data, import, export, parse, delimited file"
|
||||
PATTERN = "Build the obvious thing instead of using what the environment already provides"
|
||||
|
||||
|
||||
def retro_cli(case, tier, **kw):
|
||||
f = dict(aim="verified", moment="the export broke on a quoted field at step 2 of the run",
|
||||
cause="rows were joined by hand instead of with a quoting writer",
|
||||
change_kind="rule", change="Write delimited files with a quoting writer so fields survive",
|
||||
when=WHEN, pattern=PATTERN, short="Use a quoting writer for delimited exports.",
|
||||
topic="data files")
|
||||
f.update(kw)
|
||||
args = ["retro", "--scope", tier]
|
||||
for k in ("aim", "moment", "cause", "change_kind", "change", "when", "pattern", "short", "topic"):
|
||||
args += ["--" + k.replace("_", "-"), f[k]]
|
||||
return case.sisi(*args)
|
||||
|
||||
|
||||
class TierTests(SisiCase):
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.git_init()
|
||||
|
||||
def test_tier_decisions_round_trip(self):
|
||||
for tier in ("core", "user"):
|
||||
r = retro_cli(self, tier, moment="export %s broke on a quoted field at step 3" % tier,
|
||||
change="Write delimited files with a quoting writer so %s fields survive" % tier)
|
||||
if tier == "user":
|
||||
self.assertIn(r.returncode, (0, 4), r.stdout) # 4 = similar lesson kept as sighting
|
||||
if r.returncode == 4:
|
||||
r = self.sisi("retro", "--new", "--scope", "user", "--aim", "verified",
|
||||
"--moment", "export user broke on a quoted field at step 3",
|
||||
"--cause", "rows were joined by hand instead of with a quoting writer",
|
||||
"--change-kind", "rule",
|
||||
"--change", "Write delimited files with a quoting writer so user fields survive",
|
||||
"--when", WHEN, "--pattern", PATTERN,
|
||||
"--short", "Use a quoting writer for delimited exports.",
|
||||
"--topic", "data files")
|
||||
self.assertEqual(r.returncode, 0, r.stdout)
|
||||
con = retro.connect()
|
||||
try:
|
||||
tiers = [scope.tier_of(r[0]) for r in con.execute("SELECT scope FROM lessons ORDER BY id")]
|
||||
finally:
|
||||
con.close()
|
||||
self.assertEqual(tiers, ["core", "user"])
|
||||
for tier, text in (("core", "sisi should anticipate what is needed from what was already said"),
|
||||
("user", "always ask questions as options with a recommendation")):
|
||||
r = self.sisi("learn", "--scope", tier, text)
|
||||
self.assertEqual(r.returncode, 0, r.stdout)
|
||||
recs = store.read("learn")
|
||||
self.assertEqual([r["scope"] for r in recs], ["core", "user"])
|
||||
out = self.sisi("oracle").stdout
|
||||
self.assertIn("always ask questions as options", out)
|
||||
self.assertIn("sisi should anticipate", out) # core, until the product carries it
|
||||
|
||||
def test_missing_scope_text_asks_the_two_questions(self):
|
||||
r = self.sisi("learn", "always show options")
|
||||
self.assertEqual(r.returncode, 2)
|
||||
self.assertIn("all projects where sisi may be used", r.stdout)
|
||||
self.assertIn("every user who installs sisi", r.stdout)
|
||||
|
||||
def test_statement_naming_sisi_is_accepted_as_core_inside_sisi_repo(self):
|
||||
d = os.path.join(self.tmp, "sisi")
|
||||
os.makedirs(d)
|
||||
subprocess.run(["git", "init", "-q"], cwd=d, check=True)
|
||||
r = self.sisi("learn", "--scope", "core",
|
||||
"sisi should anticipate what I need from what I already said", cwd=d)
|
||||
self.assertEqual(r.returncode, 0, r.stdout + r.stderr)
|
||||
self.assertEqual(store.read("learn")[0]["scope"], "core")
|
||||
|
||||
def test_everywhere_migrates_to_unscoped_tier_and_still_delivers(self):
|
||||
con = retro.connect()
|
||||
lid = retro.new_lesson(con, dict(
|
||||
aim="verified", change_kind="rule", target=None,
|
||||
moment="the export broke on a quoted field at step 2 of the run",
|
||||
cause="rows were joined by hand instead of with a quoting writer",
|
||||
change="Write delimited files with a quoting writer so fields survive",
|
||||
when=WHEN, short="Use a quoting writer.", topic="data files",
|
||||
scope="user", pattern=PATTERN), self.proj, None)
|
||||
con.execute("UPDATE lessons SET scope='everywhere' WHERE id=?", (lid,))
|
||||
con.commit(); con.close()
|
||||
con = retro.connect() # migration on open
|
||||
try:
|
||||
v = con.execute("SELECT scope FROM lessons WHERE id=?", (lid,)).fetchone()[0]
|
||||
finally:
|
||||
con.close()
|
||||
self.assertEqual(v, "unscoped-tier")
|
||||
self.assertIn("Use a quoting writer", retro.tick_block(self.proj))
|
||||
brief = self.sisi("cycle", "--now").stdout
|
||||
self.assertIn("tier", brief.lower())
|
||||
|
||||
def test_digest_groups_core_user_and_project_counts(self):
|
||||
r = retro_cli(self, "core")
|
||||
self.assertEqual(r.returncode, 0, r.stdout)
|
||||
self.sisi("learn", "--scope", "user", "always ask questions as options with a recommendation")
|
||||
out = self.sisi("lessons", "digest").stdout
|
||||
self.assertIn("## In sisi itself, for every user", out)
|
||||
self.assertIn("## How you want work done", out)
|
||||
self.assertIn("waiting to be promoted", out)
|
||||
|
||||
|
||||
class PromoteTierTests(SisiCase):
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.git_init()
|
||||
self.src = os.path.join(self.tmp, "src")
|
||||
for d in ("bin", "sisi", "canon"):
|
||||
os.makedirs(os.path.join(self.src, d))
|
||||
open(os.path.join(self.src, "bin", "sisi"), "w").write("#!/bin/sh\n")
|
||||
open(os.path.join(self.src, "sisi", "cli.py"), "w").write("# cli\n")
|
||||
shutil.copy(os.path.join(REPO, "canon", "core.md"), os.path.join(self.src, "canon", "core.md"))
|
||||
os.makedirs(os.path.join(self.data), exist_ok=True)
|
||||
json.dump({"developer": {"source": self.src}}, open(os.path.join(self.data, "config.json"), "w"))
|
||||
|
||||
def core_lesson_folded_to_rule(self):
|
||||
r = retro_cli(self, "core")
|
||||
self.assertEqual(r.returncode, 0, r.stdout)
|
||||
d = os.path.join(self.data, "overlay", "rules")
|
||||
os.makedirs(d, exist_ok=True)
|
||||
with open(os.path.join(d, "quoting-writer.md"), "w") as f:
|
||||
f.write("## Write delimited files with a quoting writer\n\n"
|
||||
"Write delimited files with a quoting writer so embedded delimiters and "
|
||||
"newlines survive.\n\nWhy: hand-joined rows break on real data.\n")
|
||||
con = retro.connect()
|
||||
try:
|
||||
con.execute("UPDATE lessons SET folded_into='rule:quoting-writer' WHERE id=1")
|
||||
con.commit()
|
||||
finally:
|
||||
con.close()
|
||||
|
||||
def test_promote_lists_core_items(self):
|
||||
self.assertEqual(retro_cli(self, "core").returncode, 0)
|
||||
out = self.sisi("promote").stdout
|
||||
self.assertIn("lesson:1", out)
|
||||
|
||||
def test_promote_on_dev_install_edits_product_and_drops_personal_copy(self):
|
||||
self.core_lesson_folded_to_rule()
|
||||
overlay_file = os.path.join(self.data, "overlay", "rules", "quoting-writer.md")
|
||||
self.assertTrue(os.path.exists(overlay_file))
|
||||
r = self.sisi("promote", "lesson:1") # dry run: product untouched
|
||||
self.assertEqual(r.returncode, 0, r.stdout + r.stderr)
|
||||
self.assertNotIn("quoting-writer", open(os.path.join(self.src, "canon", "core.md")).read())
|
||||
r = self.sisi("promote", "lesson:1", "--apply")
|
||||
self.assertEqual(r.returncode, 0, r.stdout + r.stderr)
|
||||
core = open(os.path.join(self.src, "canon", "core.md")).read()
|
||||
self.assertIn("quoting writer so embedded delimiters", core)
|
||||
self.assertFalse(os.path.exists(overlay_file)) # dropped only after the product has it
|
||||
con = retro.connect()
|
||||
try:
|
||||
self.assertTrue(con.execute("SELECT promoted FROM lessons WHERE id=1").fetchone()[0])
|
||||
finally:
|
||||
con.close()
|
||||
self.assertNotIn("lesson:1", self.sisi("promote").stdout)
|
||||
|
||||
def test_export_contains_no_history_or_names(self):
|
||||
self.assertEqual(retro_cli(self, "core").returncode, 0)
|
||||
self.sisi("learn", "--scope", "core", "sisi should use what the host already provides")
|
||||
p = os.path.join(self.tmp, "contrib.md")
|
||||
r = self.sisi("promote", "--export", p)
|
||||
self.assertEqual(r.returncode, 0, r.stdout + r.stderr)
|
||||
text = open(p).read()
|
||||
self.assertIn("Write delimited files with a quoting writer", text)
|
||||
self.assertIn("sisi should use what the host already provides", text)
|
||||
self.assertNotIn("the export broke on a quoted field", text) # the moment (history)
|
||||
self.assertNotIn("rows were joined by hand", text) # the cause (history)
|
||||
self.assertNotIn(self.tmp, text)
|
||||
|
||||
def test_cycle_set_scope_to_core_and_exact_revert(self):
|
||||
con = retro.connect()
|
||||
lid = retro.new_lesson(con, dict(
|
||||
aim="verified", change_kind="rule", target=None,
|
||||
moment="the export broke on a quoted field at step 2 of the run",
|
||||
cause="rows were joined by hand instead of with a quoting writer",
|
||||
change="Write delimited files with a quoting writer so fields survive",
|
||||
when=WHEN, short="Use a quoting writer.", topic="data files",
|
||||
pattern=PATTERN), self.proj, None)
|
||||
con.commit(); con.close()
|
||||
from sisi import cycle
|
||||
doc = {"version": 1, "base": cycle.base_version(), "summary": "tier it",
|
||||
"notes": [{"lesson": lid, "action": "set-scope", "scope": "core"}]}
|
||||
p = os.path.join(self.tmp, "cyc.json")
|
||||
with open(p, "w") as f:
|
||||
json.dump(doc, f)
|
||||
r = self.sisi("cycle", "apply", p)
|
||||
self.assertEqual(r.returncode, 0, r.stdout + r.stderr)
|
||||
con = retro.connect()
|
||||
try:
|
||||
self.assertEqual(con.execute("SELECT scope FROM lessons WHERE id=?", (lid,)).fetchone()[0], "core")
|
||||
finally:
|
||||
con.close()
|
||||
r = self.sisi("cycle", "revert")
|
||||
self.assertEqual(r.returncode, 0, r.stdout + r.stderr)
|
||||
con = retro.connect()
|
||||
try:
|
||||
self.assertEqual(con.execute("SELECT scope FROM lessons WHERE id=?", (lid,)).fetchone()[0],
|
||||
"unscoped-tier")
|
||||
finally:
|
||||
con.close()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user