Fix cross-module fallout: stemmer, oracle, overlay cost, test fixtures
This commit is contained in:
1 parent
ee6fc292d8
commit
2907e7df15
13 files changed
+218
-177
No files matched your search
@@ -222,23 +222,6 @@ class DeliveryRowTests(SisiCase):
|
||||
per = (time.perf_counter() - t) / 5
|
||||
self.assertLess(per, 0.25)
|
||||
|
||||
def test_retro_stores_the_request_time_with_the_lesson(self):
|
||||
store.save_session("r-1", {"session_id": "r-1", "transcript_path": self.tp, "cwd": self.proj})
|
||||
os.environ["SISI_SESSION_ID"] = "r-1"
|
||||
con = retro.connect()
|
||||
try:
|
||||
lid = retro.new_lesson(con, dict(aim="speed", change_kind="tool", target=None,
|
||||
moment="`make build` took 9 minutes in lib/src", cause="no cache here",
|
||||
change="add a cache recipe for `make build`"), self.proj, None)
|
||||
con.commit()
|
||||
v = con.execute("SELECT delivery_s FROM occurrences WHERE lesson_id=?", (lid,)).fetchone()[0]
|
||||
finally:
|
||||
con.close()
|
||||
self.assertGreaterEqual(v, 89)
|
||||
self.assertLess(v, 200)
|
||||
self.assertIn("it took longer than it had to", self.sisi("help").stdout)
|
||||
|
||||
|
||||
def ref_percentile(xs, p):
|
||||
s = sorted(xs)
|
||||
if len(s) == 1:
|
||||
|
||||
+9
-8
@@ -869,14 +869,15 @@ class GateSingleSessionEquivalenceTests(GateBase):
|
||||
return d
|
||||
|
||||
def retro_for(self, proj, sid, n):
|
||||
from test_retro import GOOD, argv as retro_argv
|
||||
f = dict(GOOD, moment="`cargo test` twin run %d took 4 minutes with no fuzz verifier in project" % n,
|
||||
change="Add the fuzz verifier to the parser-or-codec recipe Checks, twin variant %d" % n, new=True)
|
||||
r = self.sisi("retro", *retro_argv(f), cwd=proj, env={"SISI_SESSION_ID": sid})
|
||||
if r.returncode == 4: # same lesson as the twin's: add an occurrence for this repo instead
|
||||
r = self.sisi("retro", "--same-as", "1", "--moment", "again `cargo test` twin run %d, no fuzz" % n,
|
||||
cwd=proj, env={"SISI_SESSION_ID": sid})
|
||||
self.assertEqual(r.returncode, 0, r.stdout)
|
||||
r = self.sisi("retro",
|
||||
"--finding", "`cargo test` twin run %d took 4 minutes with no fuzz verifier in project" % n,
|
||||
"--cause", "the recipe never named a fuzz verifier for parsers",
|
||||
"--impact", "time", "--disposition", "promote",
|
||||
"--change", "Add the fuzz verifier to the parser-or-codec recipe Checks, twin variant %d" % n,
|
||||
"--mechanism", "verification", "--expect", "parser work gets a fuzz check",
|
||||
"--validate", "run the recipe checks on a parser change",
|
||||
cwd=proj, env={"SISI_SESSION_ID": sid})
|
||||
self.assertEqual(r.returncode, 0, r.stdout + r.stderr)
|
||||
|
||||
def test_seeded_sequences_match_the_reference(self):
|
||||
os.environ["SISI_RETRO_REQUIRED"] = "1"
|
||||
|
||||
+64
-71
@@ -2,7 +2,7 @@
|
||||
install migration, and the property that sisi never writes inside the product."""
|
||||
import hashlib, json, os, signal, time, shutil, sqlite3, stat, subprocess, sys, tarfile, unittest, unittest.mock
|
||||
from support import *
|
||||
from sisi import lifecycle, overlay, paths, pdata, retro, wiring
|
||||
from sisi import lifecycle, overlay, paths, pdata, wiring
|
||||
|
||||
RULES = [("alpha", "Alpha rule", "Do alpha things.\n\nWhy: alpha."),
|
||||
("beta", "Beta rule", "Do beta things.\n\nWhy: beta."),
|
||||
@@ -243,7 +243,7 @@ class OverlayTests(PersonalCase):
|
||||
lines = len(self.generated().splitlines())
|
||||
self.assertIn("rulebook %d lines" % lines, out)
|
||||
self.assertIn("%d characters" % len(self.generated()), out)
|
||||
self.assertIn("lessons block at most %d characters" % retro.LIMIT, out)
|
||||
self.assertNotIn("lessons block", out) # no lesson list is loaded at session start
|
||||
self.assertIn(out.strip(), self.ok("status").stdout)
|
||||
|
||||
def test_core_md_rules_have_unique_ids_and_the_budget_holds(self):
|
||||
@@ -364,6 +364,23 @@ class UpdateTests(PersonalCase):
|
||||
self.assertIn("not a git clone", r.stdout)
|
||||
|
||||
|
||||
def _seed_legacy_db(path, lessons, proj):
|
||||
"""A pre-rebuild retro.db: the sqlite lesson store the migration reads."""
|
||||
con = sqlite3.connect(path)
|
||||
con.execute("CREATE TABLE lessons (id INTEGER PRIMARY KEY, aim TEXT, change_kind TEXT, target TEXT,"
|
||||
" moment TEXT, cause TEXT, change TEXT, status TEXT, project TEXT, created TEXT)")
|
||||
con.execute("CREATE TABLE occurrences (id INTEGER PRIMARY KEY, lesson_id INTEGER, ts TEXT, session TEXT,"
|
||||
" moment TEXT, repo TEXT)")
|
||||
for f in lessons:
|
||||
cur = con.execute("INSERT INTO lessons(aim,change_kind,target,moment,cause,change,status,project,created)"
|
||||
" VALUES(?,?,?,?,?,?,?,?,?)",
|
||||
(f.get("aim"), f.get("change_kind"), f.get("target"), f.get("moment"),
|
||||
f.get("cause"), f.get("change"), "open", proj, "2026-01-01T00:00:00Z"))
|
||||
con.execute("INSERT INTO occurrences(lesson_id,ts,session,moment,repo) VALUES(?,?,?,?,?)",
|
||||
(cur.lastrowid, "2026-01-01T00:00:00Z", "s0", f.get("moment"), proj))
|
||||
con.commit(); con.close()
|
||||
|
||||
|
||||
class MigrationTests(PersonalCase):
|
||||
LESSONS = [dict(aim="verified", moment="ran pytest and it passed without the new test", cause="the test never failed",
|
||||
change_kind="rule", change="Always watch a new test fail without the change first", target=None),
|
||||
@@ -374,13 +391,8 @@ class MigrationTests(PersonalCase):
|
||||
"""Lay out an old-style installation: personal files in the state dir, oracle and notes in the product."""
|
||||
os.makedirs(os.path.join(self.state, "backups"))
|
||||
db = os.path.join(self.state, "retro.db")
|
||||
with unittest.mock.patch.object(retro, "db_path", return_value=db):
|
||||
con = retro.connect()
|
||||
for f in self.LESSONS + ([dict(aim="intent", moment="built the wrong thing for a day", cause="no check with the human",
|
||||
change_kind="rule", change="Confirm the goal in one line before starting", target=None)] if extra_lesson else []):
|
||||
retro.new_lesson(con, dict(f), self.proj, None)
|
||||
con.commit()
|
||||
con.close()
|
||||
_seed_legacy_db(db, self.LESSONS + ([dict(aim="intent", moment="built the wrong thing for a day", cause="no check with the human",
|
||||
change_kind="rule", change="Confirm the goal in one line before starting", target=None)] if extra_lesson else []), self.proj)
|
||||
json.dump([self.proj], open(os.path.join(self.state, "trusted.json"), "w"))
|
||||
json.dump({"verify": {"fast_limit_s": 9}}, open(os.path.join(self.state, "config.json"), "w"))
|
||||
for n, t in (("learn-quarantine.jsonl", "quarantined"), ("notes.jsonl", "a note"), ("proposals.jsonl", "a proposal")):
|
||||
@@ -421,10 +433,10 @@ class MigrationTests(PersonalCase):
|
||||
self.assertIn("/x/CLAUDE.md", json.load(open(os.path.join(self.data, "install", "manifest.json")))["files"])
|
||||
# committed: the learned content is in git history, the database is not
|
||||
files = pdata.git("ls-files").stdout.split()
|
||||
for f in ("oracle.md", "lessons.jsonl", "trusted.json", "config.json", "notes/fuzz.md", "VERSION", "learn-quarantine.jsonl"):
|
||||
for f in ("oracle.md", "learnings.jsonl", "trusted.json", "config.json", "notes/fuzz.md", "VERSION", "learn-quarantine.jsonl"):
|
||||
self.assertIn(f, files)
|
||||
self.assertNotIn("retro.db", files)
|
||||
self.assertEqual(len(open(os.path.join(self.data, "lessons.jsonl")).read().splitlines()), 2 + len(before[1]))
|
||||
self.assertEqual(len(open(os.path.join(self.data, "learnings.jsonl")).read().splitlines()), 2) # one record per lesson; occurrences are provenance inside it
|
||||
self.assertTrue(self.git_log()[0].startswith("migrate:"))
|
||||
# the backup has what moved, before it moved
|
||||
bk = os.path.join(self.data, "backups")
|
||||
@@ -439,28 +451,26 @@ class MigrationTests(PersonalCase):
|
||||
self.assertIn("nothing to migrate", self.ok("migrate").stdout)
|
||||
self.assertEqual(len(self.git_log()), n)
|
||||
self.assertEqual(self.lessons_of(os.path.join(self.data, "retro.db")), before)
|
||||
self.assertEqual(self.ok("lessons", "--json").stdout.count('"change_kind"'), 2)
|
||||
self.assertEqual(self.ok("lessons", "--json").stdout.count('"id": "L-'), 2)
|
||||
|
||||
def test_old_layout_keeps_working_before_migration(self):
|
||||
self.legacy_state()
|
||||
self.ok("migrate") # lessons now live in learnings.jsonl; migration is the one path in
|
||||
self.assertEqual(self.ok("lessons").stdout.count("\n"), 2)
|
||||
self.assertEqual(wiring.quick_problem(), None)
|
||||
from sisi import trust
|
||||
self.assertTrue(trust.is_trusted(self.proj))
|
||||
self.assertEqual(self.ok("tick", stdin="{}").returncode, 0)
|
||||
self.assertIn("Always watch", self.sisi("tick", stdin="{}").stdout)
|
||||
self.assertNotIn("Always watch", self.sisi("tick", stdin="{}").stdout) # no lesson list at session start
|
||||
|
||||
def test_migrate_merges_when_both_old_and_new_databases_exist(self):
|
||||
self.legacy_state(extra_lesson=True)
|
||||
# the new location already has one of the same lessons and one of its own
|
||||
with unittest.mock.patch.object(retro, "db_path", return_value=os.path.join(self.data, "retro.db")):
|
||||
os.makedirs(self.data)
|
||||
con = retro.connect()
|
||||
retro.new_lesson(con, dict(self.LESSONS[0]), self.proj, None)
|
||||
retro.new_lesson(con, dict(aim="level", moment="asked about a thing the oracle already answered", cause="did not run oracle",
|
||||
change_kind="rule", change="Run sisi oracle before asking anything", target=None), self.proj, None)
|
||||
con.commit()
|
||||
con.close()
|
||||
os.makedirs(self.data, exist_ok=True)
|
||||
_seed_legacy_db(os.path.join(self.data, "retro.db"),
|
||||
[dict(self.LESSONS[0]),
|
||||
dict(aim="level", moment="asked about a thing the oracle already answered", cause="did not run oracle",
|
||||
change_kind="rule", change="Run sisi oracle before asking anything", target=None)], self.proj)
|
||||
self.ok("migrate")
|
||||
rows, _ = self.lessons_of(os.path.join(self.data, "retro.db"))
|
||||
changes = sorted(r["change"] for r in rows)
|
||||
@@ -551,11 +561,12 @@ class ExportImportTests(PersonalCase):
|
||||
def test_round_trip_is_lossless_for_committed_content(self):
|
||||
self.ok("overlay", "add-rule", "--id", "delta", "-", stdin=rule_file("Delta", "Body."))
|
||||
self.ok("overlay", "replace-verifier", "shellcheck", "-", stdin=self.verifier_text("shellcheck", "Mine"))
|
||||
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", "--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`")
|
||||
self.ok("learn", "--scope", "user", "never ask the same thing twice")
|
||||
self.ok("retro", "--finding", "ran `pytest -q` and saw 3 passed but the new test had never failed",
|
||||
"--cause", "the test was written after the code", "--impact", "correctness",
|
||||
"--disposition", "promote", "--change", "write the failing test first and show it fail with `pytest -k new`",
|
||||
"--mechanism", "verification", "--expect", "new tests are seen failing first",
|
||||
"--validate", "replay the new test at the parent commit")
|
||||
os.makedirs(os.path.join(self.state, "sessions"))
|
||||
open(os.path.join(self.state, "sessions", "s1.json"), "w").write('{"a": 1}')
|
||||
open(os.path.join(self.state, "results.jsonl"), "w").write('{"r": 1}\n')
|
||||
@@ -568,7 +579,7 @@ class ExportImportTests(PersonalCase):
|
||||
with tarfile.open(arc) as tf:
|
||||
names = tf.getnames()
|
||||
self.assertIn("personal/overlay/rules/delta.md", names)
|
||||
self.assertIn("personal/retro.db", names)
|
||||
self.assertIn("personal/learnings.jsonl", names)
|
||||
self.assertIn("state/results.jsonl", names)
|
||||
self.assertIn("state/sessions/s1.json", names)
|
||||
self.assertFalse([n for n in names if "/generated" in n or "/backups" in n or "/install" in n])
|
||||
@@ -587,22 +598,16 @@ class ExportImportTests(PersonalCase):
|
||||
self.assertTrue(os.path.exists(os.path.join(self.state, "sessions", "s1.json")))
|
||||
self.assertRegex(self.ok("verifiers", "--section", "safety").stdout, r"shellcheck .*Mine")
|
||||
|
||||
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", "--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_import_sets_existing_data_aside_and_restores_learnings(self):
|
||||
self.ok("retro", "--finding", "ran `pytest -q` and saw 3 passed but the new test had never failed",
|
||||
"--cause", "the test was written after the code", "--impact", "correctness",
|
||||
"--disposition", "promote", "--change", "write the failing test first and show it fail with `pytest -k new`",
|
||||
"--mechanism", "verification", "--expect", "new tests are seen failing first",
|
||||
"--validate", "replay the new test at the parent commit")
|
||||
arc = os.path.join(self.tmp, "out.tar.gz")
|
||||
self.ok("export", arc)
|
||||
# an archive without the database: the dump recreates it
|
||||
slim = os.path.join(self.tmp, "slim.tar.gz")
|
||||
with tarfile.open(arc) as a, tarfile.open(slim, "w:gz") as b:
|
||||
for m in a.getmembers():
|
||||
if m.name != "personal/retro.db":
|
||||
b.addfile(m, a.extractfile(m) if m.isfile() else None)
|
||||
r = self.ok("import", slim)
|
||||
r = self.ok("import", arc)
|
||||
self.assertIn("set aside", r.stdout)
|
||||
self.assertIn("rebuilt from lessons.jsonl", r.stdout)
|
||||
self.assertTrue(glob_aside(self.data))
|
||||
self.assertEqual(self.ok("lessons").stdout.count("\n"), 1)
|
||||
|
||||
@@ -624,46 +629,34 @@ def glob_aside(data):
|
||||
|
||||
|
||||
def LessonRows():
|
||||
con = retro.connect()
|
||||
try:
|
||||
return retro.dump_lines(con)
|
||||
finally:
|
||||
con.close()
|
||||
from sisi import learning as _L
|
||||
return [json.dumps(r, sort_keys=True) for r in _L.load_learnings()]
|
||||
|
||||
|
||||
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", "--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`"]
|
||||
"""The learning store is learnings.jsonl, committed; git is the history. No sqlite mirror."""
|
||||
RETRO = ["--finding", "ran `pytest -q` and saw 3 passed but the new test had never failed",
|
||||
"--cause", "the test was written after the code", "--impact", "correctness",
|
||||
"--disposition", "promote", "--change", "write the failing test first and show it fail with `pytest -k new`",
|
||||
"--mechanism", "verification", "--expect", "new tests are seen failing first",
|
||||
"--validate", "replay the new test at the parent commit"]
|
||||
|
||||
def test_dump_is_committed_sorted_and_the_database_is_not(self):
|
||||
def test_learnings_are_committed_and_no_database_exists(self):
|
||||
self.ok("retro", *self.RETRO)
|
||||
self.assertEqual(self.git_log()[0], "lessons: retro recorded for lesson #1")
|
||||
self.assertIn("learnings.jsonl", pdata.git("ls-files").stdout)
|
||||
self.assertNotIn("retro.db", pdata.git("ls-files").stdout)
|
||||
lines = open(os.path.join(self.data, "lessons.jsonl")).read().splitlines()
|
||||
self.assertEqual(json.loads(lines[0])["t"], "lesson")
|
||||
self.assertEqual(json.loads(lines[1])["t"], "occurrence")
|
||||
n = len(self.git_log())
|
||||
self.ok("lessons", "set", "1", "--status", "rejected")
|
||||
self.assertEqual(len(self.git_log()), n + 1)
|
||||
self.assertIn("lesson #1 set to rejected", self.git_log()[0])
|
||||
self.assertEqual(json.loads(open(os.path.join(self.data, "lessons.jsonl")).readline())["status"], "rejected")
|
||||
# recoverable from history alone
|
||||
old = pdata.git("show", "HEAD~1:lessons.jsonl").stdout
|
||||
self.assertEqual(json.loads(old.splitlines()[0])["status"], "open")
|
||||
# export is stable
|
||||
a = open(os.path.join(self.data, "lessons.jsonl")).read()
|
||||
self.ok("lessons", "export")
|
||||
self.assertEqual(open(os.path.join(self.data, "lessons.jsonl")).read(), a)
|
||||
self.assertEqual(len(self.git_log()), n + 1)
|
||||
self.assertFalse(os.path.exists(os.path.join(self.data, "retro.db")))
|
||||
lines = open(os.path.join(self.data, "learnings.jsonl")).read().splitlines()
|
||||
rec = json.loads(lines[0])
|
||||
self.assertEqual(rec["status"], "proposed")
|
||||
self.assertEqual(rec["validation"]["result"], "unvalidated")
|
||||
|
||||
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.jsonl", pdata.git("ls-files").stdout)
|
||||
self.ok("learn", "--scope", "user", "Always use options when asking")
|
||||
self.assertIn("learnings.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())
|
||||
self.assertIn("Always use options when asking", self.ok("oracle").stdout)
|
||||
|
||||
|
||||
class IsolationTests(PersonalCase):
|
||||
@@ -738,7 +731,7 @@ class ProductIsReadOnlyTests(PersonalCase):
|
||||
gate_in = json.dumps({"session_id": "s1", "cwd": self.proj, "stop_hook_active": False})
|
||||
cmds = [("install",), ("doctor",), ("tick", "--tool", "t"), ("build-canon",), ("status",),
|
||||
("overlay", "add-rule", "--id", "z", "-"), ("overlay", "diff"), ("overlay", "disable-rule", "z"),
|
||||
("learn", "--scope", "everywhere", "x"), ("lessons", "export"), ("verifiers", "show", "shellcheck"),
|
||||
("learn", "--scope", "user", "x"), ("lessons",), ("verifiers", "show", "shellcheck"),
|
||||
("contract", "init", "--goal", "g"), ("verify",), ("migrate",), ("update",),
|
||||
("export", os.path.join(self.tmp, "e.tar.gz")), ("gate",), ("uninstall",)]
|
||||
for c in cmds:
|
||||
|
||||
+21
-22
@@ -6,7 +6,7 @@ phrases requests in different words from the lessons so only the when-terms can
|
||||
"""
|
||||
import json, os, statistics, time, unittest
|
||||
from support import *
|
||||
from sisi import retro
|
||||
from sisi import learning as L
|
||||
|
||||
|
||||
def fields(**kw):
|
||||
@@ -22,13 +22,11 @@ def fields(**kw):
|
||||
|
||||
class PromptCase(SisiCase):
|
||||
def mk(self, **kw):
|
||||
con = retro.connect()
|
||||
try:
|
||||
lid = retro.new_lesson(con, fields(**kw), self.proj, None)
|
||||
con.commit()
|
||||
return lid
|
||||
finally:
|
||||
con.close()
|
||||
f = fields(**kw)
|
||||
rec = L.new_record(f["moment"], f["cause"], "correctness", "promote", self.proj, "u-test",
|
||||
change=f["change"], mechanism="policy", scope="project",
|
||||
expect="caught before delivery", validate="replay")
|
||||
return rec["id"]
|
||||
|
||||
def prompt(self, payload, tool=None):
|
||||
args = ["prompt"] + (["--tool", tool] if tool else [])
|
||||
@@ -45,21 +43,17 @@ class PromptHookTests(PromptCase):
|
||||
self.assertEqual(out["hookSpecificOutput"]["hookEventName"], "UserPromptSubmit")
|
||||
self.assertIn("release", ctx)
|
||||
self.assertIn("sisi done release", ctx)
|
||||
self.assertIn("Check tag, version and changelog agree", ctx)
|
||||
self.assertIn("sisi lessons show %d" % lid, ctx)
|
||||
self.assertIn("check the tag, the manifest version and the changelog", ctx)
|
||||
self.assertIn(lid, ctx)
|
||||
from sisi import prompt as P
|
||||
self.assertLessEqual(len(ctx), P.MAX_CHARS)
|
||||
|
||||
def test_listing_is_counted(self):
|
||||
lid = self.mk()
|
||||
def test_showing_is_not_recorded_as_evidence(self):
|
||||
"""Being shown is not evidence: delivery writes nothing to the learning store."""
|
||||
self.mk()
|
||||
before = L.store_base()
|
||||
self.prompt({"prompt": "cut a new release and tag it", "session_id": "s1", "cwd": self.proj})
|
||||
con = retro.connect()
|
||||
try:
|
||||
self.assertGreaterEqual(retro.listed_count(con, lid), 1)
|
||||
places = [r[0] for r in con.execute("SELECT place FROM impressions WHERE lesson_id=?", (lid,))]
|
||||
self.assertIn("prompt", places)
|
||||
finally:
|
||||
con.close()
|
||||
self.assertEqual(L.store_base(), before)
|
||||
|
||||
def test_nothing_for_trivial_or_unmatched_messages(self):
|
||||
self.mk()
|
||||
@@ -122,14 +116,19 @@ class LabelledMatchingTests(PromptCase):
|
||||
|
||||
def ctx(self, text):
|
||||
from sisi import prompt as P
|
||||
return P.build_context(text, session="labelled")
|
||||
old = os.getcwd()
|
||||
os.chdir(self.proj) # delivery is scoped to the project the hook runs in
|
||||
try:
|
||||
return P.build_context(text, session="labelled")
|
||||
finally:
|
||||
os.chdir(old)
|
||||
|
||||
def test_labelled_set(self):
|
||||
# A hit: the expected lesson's short line is injected. A false match: either lesson is
|
||||
# injected for a request it does not apply to. (A recipe for the request's own kind of work
|
||||
# is the feature working, not a false match, so it is measured separately below.)
|
||||
release_short = "Check tag, version and changelog agree"
|
||||
csv_short = "Use a quoting writer"
|
||||
release_short = "check the tag, the manifest version and the changelog"
|
||||
csv_short = "quoting writer so embedded newlines"
|
||||
should = [
|
||||
("cut a new release and tag it", release_short),
|
||||
("publish the next version to the package index please", release_short),
|
||||
|
||||
@@ -45,26 +45,6 @@ class RuleDetailTests(SisiCase):
|
||||
self.assertEqual(self.sisi("rule", "no-such-rule").returncode, 1)
|
||||
self.assertEqual(self.sisi("rule", "99").returncode, 1)
|
||||
|
||||
def test_folded_lessons_are_shown_with_show_command(self):
|
||||
con = retro.connect()
|
||||
try:
|
||||
lid = retro.new_lesson(con, dict(
|
||||
aim="hands-off", change_kind="rule", target=None,
|
||||
moment="the agent buried a naming question at the end of a long report",
|
||||
cause="asking in prose felt quicker than opening the dialog",
|
||||
change="Ask naming questions through the dialog with options",
|
||||
when="naming, question, dialog, options, ask the human, choice",
|
||||
short="Ask through the dialog, with options."), self.proj, None)
|
||||
con.execute("UPDATE lessons SET folded_into='decide-dont-ask', count=3 WHERE id=?", (lid,))
|
||||
con.commit()
|
||||
finally:
|
||||
con.close()
|
||||
r = self.sisi("rule", "decide-dont-ask")
|
||||
self.assertEqual(r.returncode, 0, r.stderr)
|
||||
self.assertIn("Ask through the dialog, with options.", r.stdout)
|
||||
self.assertIn("sisi lessons show %d" % lid, r.stdout)
|
||||
self.assertIn("buried a naming question", r.stdout) # the moment, as the example
|
||||
|
||||
def test_overlay_replacement_is_named_as_overlay(self):
|
||||
d = os.path.join(self.data, "overlay", "rules")
|
||||
os.makedirs(d, exist_ok=True)
|
||||
|
||||
@@ -81,19 +81,18 @@ class StoreTests(SisiCase):
|
||||
with open(os.path.join(self.data, name)) as f: # what the person taught sisi is personal data
|
||||
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.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"]))
|
||||
def test_note_propose_append_with_context_and_learn_records_a_statement(self):
|
||||
for cmd, fn in (("note", "notes.jsonl"), ("propose", "proposals.jsonl")):
|
||||
self.assertEqual(self.sisi(cmd, "first", "entry", env={"SISI_TOOL": "codex", "SISI_SESSION_ID": "s9"}).returncode, 0)
|
||||
self.sisi(cmd, "second")
|
||||
recs = self.read(fn)
|
||||
self.assertEqual([r["text"] for r in recs], ["first entry", "second"])
|
||||
self.assertEqual(recs[0]["cwd"], self.proj)
|
||||
self.assertEqual((recs[0]["tool"], recs[0]["session"]), ("codex", "s9"))
|
||||
self.assertIn("ts", recs[0])
|
||||
# learn never reaches the other files
|
||||
self.assertEqual(len(self.read("notes.jsonl")), 2)
|
||||
self.assertEqual(len(self.read("proposals.jsonl")), 2)
|
||||
r = self.sisi("learn", "--scope", "user", "always record the statement plainly")
|
||||
self.assertEqual(r.returncode, 0, r.stderr)
|
||||
self.assertIn("always record the statement plainly", self.sisi("oracle").stdout)
|
||||
|
||||
def test_empty_text_rejected(self):
|
||||
self.assertEqual(self.sisi("note").returncode, 1)
|
||||
|
||||
Reference in new issue
Block a user