@v11g/agents-rock 1.0.10 → 1.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -2
- package/package.json +1 -1
- package/plugins/business-analyst/.claude-plugin/plugin.json +2 -2
- package/plugins/business-analyst/evals/draft-scope-rich/case.yaml +4 -0
- package/plugins/business-analyst/evals/draft-scope-rich/fixture.sh +5 -0
- package/plugins/business-analyst/evals/draft-scope-rich/graders/conflict-question.md +11 -0
- package/plugins/business-analyst/evals/draft-scope-rich/graders/keep-and-exclude.md +14 -0
- package/plugins/business-analyst/evals/draft-scope-rich/graders/noise-and-shape.md +13 -0
- package/plugins/business-analyst/evals/draft-scope-rich/graders/problem-not-solution.md +13 -0
- package/plugins/business-analyst/evals/draft-scope-rich/graders/share-kept.md +11 -0
- package/plugins/business-analyst/evals/draft-scope-rich/graders/skill-fired.md +7 -0
- package/plugins/business-analyst/evals/draft-scope-rich/graders/vague-word.md +13 -0
- package/plugins/business-analyst/evals/draft-scope-rich/inputs/C1.txt +10 -0
- package/plugins/business-analyst/evals/draft-scope-rich/inputs/E1.txt +5 -0
- package/plugins/business-analyst/evals/draft-scope-rich/inputs/E2.txt +5 -0
- package/plugins/business-analyst/evals/draft-scope-rich/inputs/E3.txt +5 -0
- package/plugins/business-analyst/evals/draft-scope-rich/prompt.md +9 -0
- package/plugins/business-analyst/evals/draft-scope-thin/case.yaml +4 -0
- package/plugins/business-analyst/evals/draft-scope-thin/fixture.sh +4 -0
- package/plugins/business-analyst/evals/draft-scope-thin/graders/no-invention.md +18 -0
- package/plugins/business-analyst/evals/draft-scope-thin/graders/skill-fired.md +7 -0
- package/plugins/business-analyst/evals/draft-scope-thin/inputs/E1.txt +5 -0
- package/plugins/business-analyst/evals/draft-scope-thin/prompt.md +8 -0
- package/plugins/business-analyst/skills/business-analyst/scripts/__pycache__/review_data.cpython-312.pyc +0 -0
- package/plugins/business-analyst/skills/business-analyst/scripts/__pycache__/review_layout.cpython-312.pyc +0 -0
- package/plugins/business-analyst/skills/business-analyst/scripts/__pycache__/review_page.cpython-312.pyc +0 -0
- package/plugins/business-analyst/skills/business-analyst/scripts/__pycache__/scope_checks.cpython-312.pyc +0 -0
- package/plugins/business-analyst/skills/business-analyst/scripts/__pycache__/scope_render.cpython-312.pyc +0 -0
- package/plugins/business-analyst/skills/business-analyst/scripts/__pycache__/validate.cpython-312.pyc +0 -0
- package/plugins/business-analyst/skills/draft-scope/SKILL.md +46 -0
- package/plugins/business-analyst/skills/draft-scope/references/credits.md +12 -0
- package/plugins/business-analyst/skills/draft-scope/references/draft-schema.md +44 -0
- package/plugins/business-analyst/skills/draft-scope/references/rules.md +24 -0
- package/plugins/business-analyst/skills/draft-scope/scripts/__pycache__/docx_body.cpython-312.pyc +0 -0
- package/plugins/business-analyst/skills/draft-scope/scripts/__pycache__/docx_flow.cpython-312.pyc +0 -0
- package/plugins/business-analyst/skills/draft-scope/scripts/__pycache__/docx_package.cpython-312.pyc +0 -0
- package/plugins/business-analyst/skills/draft-scope/scripts/__pycache__/docx_xml.cpython-312.pyc +0 -0
- package/plugins/business-analyst/skills/draft-scope/scripts/__pycache__/draft_quotes.cpython-312.pyc +0 -0
- package/plugins/business-analyst/skills/draft-scope/scripts/__pycache__/draft_rules.cpython-312.pyc +0 -0
- package/plugins/business-analyst/skills/draft-scope/scripts/__pycache__/draft_schema.cpython-312.pyc +0 -0
- package/plugins/business-analyst/skills/draft-scope/scripts/build_docx.py +36 -0
- package/plugins/business-analyst/skills/draft-scope/scripts/check.py +53 -0
- package/plugins/business-analyst/skills/draft-scope/scripts/docx_body.py +58 -0
- package/plugins/business-analyst/skills/draft-scope/scripts/docx_flow.py +52 -0
- package/plugins/business-analyst/skills/draft-scope/scripts/docx_package.py +62 -0
- package/plugins/business-analyst/skills/draft-scope/scripts/docx_xml.py +44 -0
- package/plugins/business-analyst/skills/draft-scope/scripts/draft_quotes.py +49 -0
- package/plugins/business-analyst/skills/draft-scope/scripts/draft_rules.py +106 -0
- package/plugins/business-analyst/skills/draft-scope/scripts/draft_schema.py +87 -0
- package/plugins/business-analyst/skills/draft-scope/scripts/test/build-docx.test.mjs +76 -0
- package/plugins/business-analyst/skills/draft-scope/scripts/test/check-rules.test.mjs +131 -0
- package/plugins/business-analyst/skills/draft-scope/scripts/test/check-shape.test.mjs +70 -0
- package/plugins/business-analyst/skills/draft-scope/scripts/test/fixtures/draft-pass.json +40 -0
- package/plugins/business-analyst/skills/draft-scope/scripts/test/fixtures/sources/C1.txt +7 -0
- package/plugins/business-analyst/skills/draft-scope/scripts/test/fixtures/sources/E1.txt +5 -0
- package/plugins/business-analyst/skills/draft-scope/scripts/test/gates.test.mjs +39 -0
- package/plugins/business-analyst/skills/draft-scope/scripts/test/helpers.mjs +30 -0
- package/plugins/business-analyst/skills/draft-scope/scripts/test/skill-files.test.mjs +59 -0
- package/plugins/business-analyst/skills/draft-scope/steps/assumptions.md +24 -0
- package/plugins/business-analyst/skills/draft-scope/steps/check.md +24 -0
- package/plugins/business-analyst/skills/draft-scope/steps/discover.md +53 -0
- package/plugins/business-analyst/skills/draft-scope/steps/draft.md +64 -0
- package/plugins/solution-architect/.claude-plugin/plugin.json +1 -1
- package/plugins/solution-architect/skills/analyze-requirements/SKILL.md +8 -7
- package/plugins/solution-architect/skills/analyze-requirements/assets/section-help.json +5 -5
- package/plugins/solution-architect/skills/analyze-requirements/assets/viewer-template.html +15 -3
- package/plugins/solution-architect/skills/analyze-requirements/evals/evals.json +50 -6
- package/plugins/solution-architect/skills/analyze-requirements/evals/fixtures/ba-package-citations/requirements.json +31 -0
- package/plugins/solution-architect/skills/analyze-requirements/evals/fixtures/ba-package-citations/requirements.md +17 -0
- package/plugins/solution-architect/skills/analyze-requirements/evals/fixtures/transcript-citations/C1-kickoff-call.txt +16 -0
- package/plugins/solution-architect/skills/analyze-requirements/evals/fixtures/transcript-citations/E1-intro-email.md +9 -0
- package/plugins/solution-architect/skills/analyze-requirements/references/extract.md +108 -0
- package/plugins/solution-architect/skills/analyze-requirements/references/interview.md +39 -5
- package/plugins/solution-architect/skills/analyze-requirements/references/project-types.md +1 -1
- package/plugins/solution-architect/skills/analyze-requirements/references/quality-goals.md +84 -0
- package/plugins/solution-architect/skills/analyze-requirements/references/research.md +1 -1
- package/plugins/solution-architect/skills/analyze-requirements/references/rewriting.md +7 -2
- package/plugins/solution-architect/skills/analyze-requirements/references/viewer.md +10 -6
- package/plugins/solution-architect/skills/analyze-requirements/references/writing.md +45 -3
- package/plugins/solution-architect/skills/analyze-requirements/scripts/ba-facts.mjs +32 -0
- package/plugins/solution-architect/skills/analyze-requirements/scripts/check-quotes.mjs +39 -0
- package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/ba-package.mjs +75 -0
- package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/doc-links.mjs +19 -7
- package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/doc-routes.mjs +1 -1
- package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/inputs.mjs +42 -11
- package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/md-render.mjs +15 -4
- package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/section-help.mjs +1 -1
- package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/strategy-sections.mjs +30 -0
- package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/validate-provenance.mjs +14 -2
- package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/validate-quotes.mjs +55 -0
- package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/validate-strategy.mjs +65 -0
- package/plugins/solution-architect/skills/analyze-requirements/scripts/render.mjs +18 -5
- package/plugins/solution-architect/skills/analyze-requirements/scripts/test/ba-facts-cli.test.mjs +55 -0
- package/plugins/solution-architect/skills/analyze-requirements/scripts/test/ba-package-cli.test.mjs +101 -0
- package/plugins/solution-architect/skills/analyze-requirements/scripts/test/ba-package.test.mjs +115 -0
- package/plugins/solution-architect/skills/analyze-requirements/scripts/test/browser.test.mjs +50 -2
- package/plugins/solution-architect/skills/analyze-requirements/scripts/test/check-quotes-cli.test.mjs +49 -0
- package/plugins/solution-architect/skills/analyze-requirements/scripts/test/doc-links.test.mjs +49 -4
- package/plugins/solution-architect/skills/analyze-requirements/scripts/test/extract-workflow.test.mjs +69 -0
- package/plugins/solution-architect/skills/analyze-requirements/scripts/test/inputs.test.mjs +14 -0
- package/plugins/solution-architect/skills/analyze-requirements/scripts/test/md-render.test.mjs +19 -5
- package/plugins/solution-architect/skills/analyze-requirements/scripts/test/record-cli.test.mjs +1 -1
- package/plugins/solution-architect/skills/analyze-requirements/scripts/test/render.test.mjs +69 -2
- package/plugins/solution-architect/skills/analyze-requirements/scripts/test/rewriting.test.mjs +1 -1
- package/plugins/solution-architect/skills/analyze-requirements/scripts/test/section-help.test.mjs +6 -0
- package/plugins/solution-architect/skills/analyze-requirements/scripts/test/validate-provenance.test.mjs +19 -0
- package/plugins/solution-architect/skills/analyze-requirements/scripts/test/validate-quotes-cli.test.mjs +58 -0
- package/plugins/solution-architect/skills/analyze-requirements/scripts/test/validate-quotes.test.mjs +81 -0
- package/plugins/solution-architect/skills/analyze-requirements/scripts/test/validate-strategy-cli.test.mjs +32 -0
- package/plugins/solution-architect/skills/analyze-requirements/scripts/test/validate-strategy.test.mjs +118 -0
- package/plugins/solution-architect/skills/analyze-requirements/scripts/validate.mjs +17 -6
- package/plugins/solution-architect/skills/analyze-requirements/workflows/extract.js +51 -0
- package/plugins/solution-architect/skills/estimate/workflow-based/assets/estimate-components.html +73 -9
- package/plugins/solution-architect/skills/estimate/workflow-based/assets/score-review.html +73 -9
- package/plugins/solution-architect/skills/estimate/workflow-based/scripts/build-template.mjs +14 -1
- package/plugins/solution-architect/skills/estimate/workflow-based/scripts/template/also-builds.css +3 -0
- package/plugins/solution-architect/skills/estimate/workflow-based/scripts/template/also-builds.js +16 -0
- package/plugins/solution-architect/skills/estimate/workflow-based/scripts/template/link-picker.css +8 -0
- package/plugins/solution-architect/skills/estimate/workflow-based/scripts/template/link-picker.js +43 -0
- package/plugins/solution-architect/skills/estimate/workflow-based/scripts/test/also-builds-browser.test.mjs +59 -0
- package/plugins/solution-architect/skills/estimate/workflow-based/scripts/test/link-picker-browser.test.mjs +83 -0
- package/plugins/solution-architect/skills/estimate/workflow-based/scripts/test/stage.mjs +19 -1
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"""The DOCX package around document.xml: content types, relationships, the
|
|
2
|
+
built-in styles the body uses, one bullet list. Standard Word styles only."""
|
|
3
|
+
import zipfile
|
|
4
|
+
|
|
5
|
+
XML = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n'
|
|
6
|
+
W = 'xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"'
|
|
7
|
+
REL = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships'
|
|
8
|
+
PKG_REL = 'http://schemas.openxmlformats.org/package/2006/relationships'
|
|
9
|
+
MAIN = 'application/vnd.openxmlformats-officedocument.wordprocessingml'
|
|
10
|
+
|
|
11
|
+
CONTENT_TYPES = (f'{XML}<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">'
|
|
12
|
+
'<Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/>'
|
|
13
|
+
'<Default Extension="xml" ContentType="application/xml"/>'
|
|
14
|
+
f'<Override PartName="/word/document.xml" ContentType="{MAIN}.document.main+xml"/>'
|
|
15
|
+
f'<Override PartName="/word/styles.xml" ContentType="{MAIN}.styles+xml"/>'
|
|
16
|
+
f'<Override PartName="/word/numbering.xml" ContentType="{MAIN}.numbering+xml"/></Types>')
|
|
17
|
+
ROOT_RELS = (f'{XML}<Relationships xmlns="{PKG_REL}">'
|
|
18
|
+
f'<Relationship Id="rId1" Type="{REL}/officeDocument" Target="word/document.xml"/></Relationships>')
|
|
19
|
+
DOC_RELS = (f'{XML}<Relationships xmlns="{PKG_REL}">'
|
|
20
|
+
f'<Relationship Id="rIdStyles" Type="{REL}/styles" Target="styles.xml"/>'
|
|
21
|
+
f'<Relationship Id="rIdNumbering" Type="{REL}/numbering" Target="numbering.xml"/></Relationships>')
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def p_style(sid, name, props):
|
|
25
|
+
return (f'<w:style w:type="paragraph" w:styleId="{sid}"><w:name w:val="{name}"/>'
|
|
26
|
+
f'<w:basedOn w:val="Normal"/><w:next w:val="Normal"/>{props}</w:style>')
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def heading(level, size):
|
|
30
|
+
before = 360 if level == 1 else 240
|
|
31
|
+
return p_style(f'Heading{level}', f'heading {level}',
|
|
32
|
+
f'<w:pPr><w:keepNext/><w:spacing w:before="{before}" w:after="120"/>'
|
|
33
|
+
f'<w:outlineLvl w:val="{level - 1}"/></w:pPr><w:rPr><w:b/><w:sz w:val="{size}"/></w:rPr>')
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
BORDER = ''.join(f'<w:{b} w:val="single" w:sz="4" w:space="0" w:color="D9DDE3"/>'
|
|
37
|
+
for b in ('top', 'left', 'bottom', 'right', 'insideH', 'insideV'))
|
|
38
|
+
STYLES = (f'{XML}<w:styles {W}><w:docDefaults><w:rPrDefault><w:rPr>'
|
|
39
|
+
'<w:rFonts w:ascii="Calibri" w:hAnsi="Calibri" w:cs="Calibri"/><w:sz w:val="22"/></w:rPr></w:rPrDefault>'
|
|
40
|
+
'<w:pPrDefault><w:pPr><w:spacing w:after="120" w:line="276" w:lineRule="auto"/></w:pPr></w:pPrDefault></w:docDefaults>'
|
|
41
|
+
'<w:style w:type="paragraph" w:default="1" w:styleId="Normal"><w:name w:val="Normal"/></w:style>'
|
|
42
|
+
+ p_style('Title', 'Title', '<w:pPr><w:spacing w:after="80"/></w:pPr><w:rPr><w:b/><w:sz w:val="44"/></w:rPr>')
|
|
43
|
+
+ p_style('Subtitle', 'Subtitle', '<w:rPr><w:color w:val="5C6470"/><w:sz w:val="24"/></w:rPr>')
|
|
44
|
+
+ heading(1, 32) + heading(2, 24) + heading(3, 22)
|
|
45
|
+
+ p_style('ListParagraph', 'List Paragraph', '<w:pPr><w:ind w:left="720"/></w:pPr>')
|
|
46
|
+
+ f'<w:style w:type="table" w:styleId="TableGrid"><w:name w:val="Table Grid"/><w:tblPr><w:tblBorders>{BORDER}</w:tblBorders>'
|
|
47
|
+
'<w:tblCellMar><w:top w:w="60" w:type="dxa"/><w:left w:w="100" w:type="dxa"/>'
|
|
48
|
+
'<w:bottom w:w="60" w:type="dxa"/><w:right w:w="100" w:type="dxa"/></w:tblCellMar></w:tblPr></w:style></w:styles>')
|
|
49
|
+
NUMBERING = (f'{XML}<w:numbering {W}><w:abstractNum w:abstractNumId="0"><w:multiLevelType w:val="hybridMultilevel"/>'
|
|
50
|
+
'<w:lvl w:ilvl="0"><w:start w:val="1"/><w:numFmt w:val="bullet"/><w:lvlText w:val="•"/>'
|
|
51
|
+
'<w:lvlJc w:val="left"/><w:pPr><w:ind w:left="720" w:hanging="360"/></w:pPr></w:lvl>'
|
|
52
|
+
'</w:abstractNum><w:num w:numId="1"><w:abstractNumId w:val="0"/></w:num></w:numbering>')
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def write_docx(path, document):
|
|
56
|
+
"""[Content_Types].xml first, as Word expects; deflate-compressed."""
|
|
57
|
+
parts = [('[Content_Types].xml', CONTENT_TYPES), ('_rels/.rels', ROOT_RELS),
|
|
58
|
+
('word/document.xml', document), ('word/_rels/document.xml.rels', DOC_RELS),
|
|
59
|
+
('word/styles.xml', STYLES), ('word/numbering.xml', NUMBERING)]
|
|
60
|
+
with zipfile.ZipFile(path, 'w', zipfile.ZIP_DEFLATED) as z:
|
|
61
|
+
for name, xml in parts:
|
|
62
|
+
z.writestr(name, xml.encode('utf-8'))
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"""WordprocessingML pieces: paragraphs, bullet lists, tables (styles in docx_package.py)."""
|
|
2
|
+
import re
|
|
3
|
+
|
|
4
|
+
TEXT_WIDTH = 9638 # twips: A4 width less two 2 cm margins
|
|
5
|
+
CONTROL = re.compile('[\x00-\x08\x0b\x0c\x0e-\x1f]')
|
|
6
|
+
BULLET = ('<w:pPr><w:pStyle w:val="ListParagraph"/>'
|
|
7
|
+
'<w:numPr><w:ilvl w:val="0"/><w:numId w:val="1"/></w:numPr></w:pPr>')
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def xml_text(text):
|
|
11
|
+
clean = CONTROL.sub('', str(text))
|
|
12
|
+
return clean.replace('&', '&').replace('<', '<').replace('>', '>')
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def run(text, bold=False):
|
|
16
|
+
props = '<w:rPr><w:b/></w:rPr>' if bold else ''
|
|
17
|
+
return f'<w:r>{props}<w:t xml:space="preserve">{xml_text(text)}</w:t></w:r>'
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def para(text, style=None):
|
|
21
|
+
if not text:
|
|
22
|
+
return ''
|
|
23
|
+
props = f'<w:pPr><w:pStyle w:val="{style}"/></w:pPr>' if style else ''
|
|
24
|
+
return f'<w:p>{props}{run(text)}</w:p>'
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def bullets(items):
|
|
28
|
+
return ''.join(f'<w:p>{BULLET}{run(t)}</w:p>' for t in items)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def row(cells, head):
|
|
32
|
+
props = '<w:trPr><w:tblHeader/></w:trPr>' if head else ''
|
|
33
|
+
tcs = ''.join(f'<w:tc><w:p>{run(c, head)}</w:p></w:tc>' for c in cells)
|
|
34
|
+
return f'<w:tr>{props}{tcs}</w:tr>'
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def table(head, rows):
|
|
38
|
+
"""A bordered table, or a 'None.' line when there are no rows."""
|
|
39
|
+
if not rows:
|
|
40
|
+
return para('None.')
|
|
41
|
+
grid = ''.join(f'<w:gridCol w:w="{TEXT_WIDTH // len(head)}"/>' for _ in head)
|
|
42
|
+
body = row(head, True) + ''.join(row(r, False) for r in rows)
|
|
43
|
+
return ('<w:tbl><w:tblPr><w:tblStyle w:val="TableGrid"/><w:tblW w:w="5000" w:type="pct"/></w:tblPr>'
|
|
44
|
+
f'<w:tblGrid>{grid}</w:tblGrid>{body}</w:tbl><w:p/>')
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"""Every problem quote must appear word for word in its source file."""
|
|
2
|
+
import difflib
|
|
3
|
+
import os
|
|
4
|
+
import re
|
|
5
|
+
|
|
6
|
+
MARKS = str.maketrans({'“': '"', '”': '"', '‘': "'", '’': "'", '–': '-', '—': '-', '‑': '-'})
|
|
7
|
+
REPLY = re.compile(r'^[ \t]*>+[ \t]?', re.M)
|
|
8
|
+
SENTENCE = re.compile(r'(?<=[.!?])\s+|\n+')
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def plain(text):
|
|
12
|
+
"""Text as the PO reads it: no email reply markers, one kind of quote mark and dash, single spaces."""
|
|
13
|
+
return ' '.join(REPLY.sub('', text).translate(MARKS).split())
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def norm(text):
|
|
17
|
+
"""What a quote is matched on: plain text, any case, without wrapping quote marks."""
|
|
18
|
+
return plain(text).strip('"\'').casefold()
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def read_sources(draft, base):
|
|
22
|
+
"""{id: text} for every source file found, plus findings for the missing ones."""
|
|
23
|
+
texts, out = {}, []
|
|
24
|
+
for s in draft['sources']:
|
|
25
|
+
path = os.path.join(base, s['file'])
|
|
26
|
+
if os.path.isfile(path):
|
|
27
|
+
with open(path, encoding='utf-8') as f:
|
|
28
|
+
texts[s['id']] = f.read()
|
|
29
|
+
else:
|
|
30
|
+
out.append(f"sources: {s['id']} file {s['file']} not found")
|
|
31
|
+
return texts, out
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def closest(quote, raw):
|
|
35
|
+
sentences = [plain(s) for s in SENTENCE.split(REPLY.sub('', raw)) if s.strip()]
|
|
36
|
+
score = lambda s: difflib.SequenceMatcher(None, norm(quote), s.casefold()).ratio()
|
|
37
|
+
return max(sentences, key=score, default='')
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def quote_findings(draft, base):
|
|
41
|
+
texts, out = read_sources(draft, base)
|
|
42
|
+
for i, p in enumerate(draft['problems']):
|
|
43
|
+
for j, q in enumerate(p['quotes']):
|
|
44
|
+
raw = texts.get(q['source'])
|
|
45
|
+
if raw is None or norm(q['text']) in norm(raw):
|
|
46
|
+
continue
|
|
47
|
+
hint = closest(q['text'], raw)
|
|
48
|
+
out.append(f"problems[{i}].quotes[{j}]: not word for word in {q['source']}; closest: \"{hint}\"")
|
|
49
|
+
return out
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"""Rules check.py applies to a well-shaped draft: references, coverage, limits, banned words."""
|
|
2
|
+
import re
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def source_refs(draft):
|
|
6
|
+
"""(where, id) for every field that must name a source."""
|
|
7
|
+
for i, p in enumerate(draft['problems']):
|
|
8
|
+
for j, q in enumerate(p['quotes']):
|
|
9
|
+
yield f'problems[{i}].quotes[{j}]', q['source']
|
|
10
|
+
for j, x in enumerate(draft['scope']['exclusions']):
|
|
11
|
+
yield f'scope.exclusions[{j}]', x['source']
|
|
12
|
+
for i, s in enumerate(draft['systems']):
|
|
13
|
+
for key in ('workflows', 'features'):
|
|
14
|
+
for j, x in enumerate(s[key]):
|
|
15
|
+
yield f'systems[{i}].{key}[{j}]', x['source']
|
|
16
|
+
for i, a in enumerate(draft['assumptions']):
|
|
17
|
+
yield f'assumptions[{i}]', a['source']
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def problem_refs(draft):
|
|
21
|
+
"""(where, id) for every field that must name a problem."""
|
|
22
|
+
for i, s in enumerate(draft['systems']):
|
|
23
|
+
yield f'systems[{i}]', s['problem']
|
|
24
|
+
for j, f in enumerate(s['features']):
|
|
25
|
+
yield f'systems[{i}].features[{j}]', f['problem']
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def ref_findings(draft):
|
|
29
|
+
sources = {s['id'] for s in draft['sources']}
|
|
30
|
+
problems = {p['id'] for p in draft['problems']}
|
|
31
|
+
features = {f['name'] for s in draft['systems'] for f in s['features']}
|
|
32
|
+
out = [f'{w}: unknown source {r}' for w, r in source_refs(draft) if r not in sources]
|
|
33
|
+
out += [f'{w}: unknown problem {r}' for w, r in problem_refs(draft) if r not in problems]
|
|
34
|
+
out += [f"assumptions[{i}]: unknown feature {a['feature']}"
|
|
35
|
+
for i, a in enumerate(draft['assumptions']) if a['feature'] not in features]
|
|
36
|
+
for i, q in enumerate(draft['questions']):
|
|
37
|
+
out += [f'questions[{i}]: unknown ref {r}' for r in q['refs'] if r not in sources | problems]
|
|
38
|
+
return out
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
MAX_PROBLEMS = 6
|
|
42
|
+
MAX_ASSUMPTIONS = 8
|
|
43
|
+
BANNED = ['fast', 'quick', 'easy', 'simple', 'user-friendly', 'intuitive', 'flexible', 'robust',
|
|
44
|
+
'seamless', 'efficient', 'optimal', 'appropriate', 'various', 'etc', 'some', 'many',
|
|
45
|
+
'several', 'as needed']
|
|
46
|
+
QUOTED = re.compile('|'.join([r'"[^"]*"', r'“[^”]*”', r"(?<!\w)'[^']*'(?!\w)", r'‘[^’]*’']))
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def words(text):
|
|
50
|
+
return len([w for w in text.split() if any(c.isalnum() for c in w)])
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def coverage_findings(draft):
|
|
54
|
+
hit = {f['problem'] for s in draft['systems'] for f in s['features']}
|
|
55
|
+
hit |= {r for q in draft['questions'] for r in q['refs']}
|
|
56
|
+
return [f"{p['id']}: no feature or client question points at it"
|
|
57
|
+
for p in draft['problems'] if p['id'] not in hit]
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def count_findings(draft):
|
|
61
|
+
n, a = len(draft['problems']), len(draft['assumptions'])
|
|
62
|
+
out = [f'problems: {n}, at least 1'] if n < 1 else []
|
|
63
|
+
out += [f"{p['id']}: no quote" for p in draft['problems'] if not p['quotes']]
|
|
64
|
+
out += [f'problems: {n}, at most {MAX_PROBLEMS}'] if n > MAX_PROBLEMS else []
|
|
65
|
+
return out + ([f'assumptions: {a}, at most {MAX_ASSUMPTIONS}'] if a > MAX_ASSUMPTIONS else [])
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def limit_findings(draft):
|
|
69
|
+
out = count_findings(draft)
|
|
70
|
+
for i, s in enumerate(draft['systems']):
|
|
71
|
+
for j, w in enumerate(s['workflows']):
|
|
72
|
+
out += [f'systems[{i}].workflows[{j}]: no steps'] if not w['steps'] else []
|
|
73
|
+
out += [f'systems[{i}].workflows[{j}]: step "{st}" has {words(st)} words, at most 5'
|
|
74
|
+
for st in w['steps'] if not 1 <= words(st) <= 5]
|
|
75
|
+
out += [f"systems[{i}].features[{j}]: name \"{f['name']}\" has {words(f['name'])} words, 2 to 6"
|
|
76
|
+
for j, f in enumerate(s['features']) if not 2 <= words(f['name']) <= 6]
|
|
77
|
+
return out
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def text_fields(draft):
|
|
81
|
+
"""(where, text) for every field the PO reads that is not a quote."""
|
|
82
|
+
yield 'scope.covered', draft['scope']['covered']
|
|
83
|
+
for i, p in enumerate(draft['problems']):
|
|
84
|
+
yield f'problems[{i}].text', p['text']
|
|
85
|
+
for j, x in enumerate(draft['scope']['exclusions']):
|
|
86
|
+
yield f'scope.exclusions[{j}].text', x['text']
|
|
87
|
+
for i, s in enumerate(draft['systems']):
|
|
88
|
+
yield f'systems[{i}].name', s['name']
|
|
89
|
+
yield f'systems[{i}].purpose', s['purpose']
|
|
90
|
+
for j, f in enumerate(s['features']):
|
|
91
|
+
yield f'systems[{i}].features[{j}].name', f['name']
|
|
92
|
+
yield f'systems[{i}].features[{j}].does', f['does']
|
|
93
|
+
for i, a in enumerate(draft['assumptions']):
|
|
94
|
+
yield f'assumptions[{i}].text', a['text']
|
|
95
|
+
for i, q in enumerate(draft['questions']):
|
|
96
|
+
for key in ('text', 'why', 'assume'):
|
|
97
|
+
yield f'questions[{i}].{key}', q[key]
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def word_findings(draft):
|
|
101
|
+
out = []
|
|
102
|
+
for where, text in text_fields(draft):
|
|
103
|
+
plain = QUOTED.sub(' ', text)
|
|
104
|
+
out += [f'{where}: vague word "{w}"' for w in BANNED
|
|
105
|
+
if re.search(rf'(?<![\w-]){re.escape(w)}(?![\w-])', plain, re.IGNORECASE)]
|
|
106
|
+
return out
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"""Shape of draft.json (references/draft-schema.md): required fields, types, ids and kinds."""
|
|
2
|
+
import re
|
|
3
|
+
|
|
4
|
+
SOURCE_ID = re.compile(r'^[ECN][1-9][0-9]*$')
|
|
5
|
+
PROBLEM_ID = re.compile(r'^P[1-9][0-9]*$')
|
|
6
|
+
KINDS = ('email', 'call', 'note')
|
|
7
|
+
FLOW_KINDS = ('main', 'side', 'sub')
|
|
8
|
+
REASONS = ('owned-elsewhere', 'later-phase', 'no-detail')
|
|
9
|
+
|
|
10
|
+
TOP = [('client', str), ('date', str), ('sources', list), ('problems', list),
|
|
11
|
+
('scope', dict), ('systems', list), ('assumptions', list), ('questions', list)]
|
|
12
|
+
SCOPE = [('covered', str), ('exclusions', list)]
|
|
13
|
+
ITEMS = {
|
|
14
|
+
'sources': [('id', str), ('kind', str), ('date', str), ('who', str), ('file', str)],
|
|
15
|
+
'problems': [('id', str), ('text', str), ('quotes', list)],
|
|
16
|
+
'systems': [('name', str), ('purpose', str), ('problem', str), ('workflows', list), ('features', list)],
|
|
17
|
+
'assumptions': [('text', str), ('feature', str), ('source', str)],
|
|
18
|
+
'questions': [('text', str), ('why', str), ('assume', str), ('refs', list)],
|
|
19
|
+
}
|
|
20
|
+
NESTED = {
|
|
21
|
+
'quotes': [('source', str), ('text', str)],
|
|
22
|
+
'workflows': [('kind', str), ('steps', list), ('source', str)],
|
|
23
|
+
'features': [('name', str), ('does', str), ('problem', str), ('source', str)],
|
|
24
|
+
'exclusions': [('text', str), ('reason', str), ('source', str)],
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def missing(obj, fields, where):
|
|
29
|
+
if not isinstance(obj, dict):
|
|
30
|
+
return [f'{where}: not an object']
|
|
31
|
+
return [f'{where}: {key} missing or not {kind.__name__}'
|
|
32
|
+
for key, kind in fields if not isinstance(obj.get(key), kind)]
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def nested_items(draft):
|
|
36
|
+
"""(where, item, fields) for every item inside problems, systems and scope."""
|
|
37
|
+
for i, p in enumerate(draft['problems']):
|
|
38
|
+
for j, q in enumerate(p['quotes']):
|
|
39
|
+
yield f'problems[{i}].quotes[{j}]', q, NESTED['quotes']
|
|
40
|
+
for i, s in enumerate(draft['systems']):
|
|
41
|
+
for key in ('workflows', 'features'):
|
|
42
|
+
for j, x in enumerate(s[key]):
|
|
43
|
+
yield f'systems[{i}].{key}[{j}]', x, NESTED[key]
|
|
44
|
+
for j, x in enumerate(draft['scope']['exclusions']):
|
|
45
|
+
yield f'scope.exclusions[{j}]', x, NESTED['exclusions']
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def outer_findings(draft):
|
|
49
|
+
out = missing(draft, TOP, 'draft')
|
|
50
|
+
if out:
|
|
51
|
+
return out
|
|
52
|
+
out = missing(draft['scope'], SCOPE, 'scope')
|
|
53
|
+
for name, fields in ITEMS.items():
|
|
54
|
+
for i, item in enumerate(draft[name]):
|
|
55
|
+
out += missing(item, fields, f'{name}[{i}]')
|
|
56
|
+
return out
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def id_findings(draft):
|
|
60
|
+
out = []
|
|
61
|
+
for name, pattern in (('sources', SOURCE_ID), ('problems', PROBLEM_ID)):
|
|
62
|
+
ids = [x['id'] for x in draft[name]]
|
|
63
|
+
out += [f'{name}: bad id {i}' for i in ids if not pattern.match(i)]
|
|
64
|
+
out += [f'{name}: duplicate id {i}' for i in sorted(set(ids)) if ids.count(i) > 1]
|
|
65
|
+
return out
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def enum_findings(draft):
|
|
69
|
+
out = [f"sources: {s['id']} kind {s['kind']} is not email, call or note"
|
|
70
|
+
for s in draft['sources'] if s['kind'] not in KINDS]
|
|
71
|
+
for i, s in enumerate(draft['systems']):
|
|
72
|
+
out += [f"systems[{i}].workflows[{j}]: kind {w['kind']} is not main, side or sub"
|
|
73
|
+
for j, w in enumerate(s['workflows']) if w['kind'] not in FLOW_KINDS]
|
|
74
|
+
out += [f"scope.exclusions[{j}]: reason {x['reason']} is not owned-elsewhere, later-phase or no-detail"
|
|
75
|
+
for j, x in enumerate(draft['scope']['exclusions']) if x['reason'] not in REASONS]
|
|
76
|
+
return out
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def shape_findings(draft):
|
|
80
|
+
out = outer_findings(draft)
|
|
81
|
+
if out:
|
|
82
|
+
return out
|
|
83
|
+
for where, item, fields in nested_items(draft):
|
|
84
|
+
out += missing(item, fields, where)
|
|
85
|
+
if out:
|
|
86
|
+
return out
|
|
87
|
+
return id_findings(draft) + enum_findings(draft)
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { test } from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import { execFileSync } from 'node:child_process';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
import { py, stage } from './helpers.mjs';
|
|
6
|
+
|
|
7
|
+
const READ = 'import sys, zipfile; z = zipfile.ZipFile(sys.argv[1]); print("\\n".join(z.namelist())); print("@@"); print(z.read("word/document.xml").decode())';
|
|
8
|
+
|
|
9
|
+
function built(mutate) {
|
|
10
|
+
const dir = stage(mutate);
|
|
11
|
+
const out = join(dir, 'draft-scope.docx');
|
|
12
|
+
const r = py('build_docx.py', ['--draft', join(dir, 'draft.json'), '--out', out]);
|
|
13
|
+
assert.equal(r.code, 0, r.err);
|
|
14
|
+
const [names, xml] = execFileSync('python3', ['-c', READ, out], { encoding: 'utf8' }).split('@@\n');
|
|
15
|
+
return { names: names.trim().split('\n'), xml, text: xml.replace(/<[^>]+>/g, ' ').replace(/\s+/g, ' ') };
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
test('the package holds the Word parts, content types first', () => {
|
|
19
|
+
const { names } = built();
|
|
20
|
+
assert.equal(names[0], '[Content_Types].xml');
|
|
21
|
+
for (const p of ['_rels/.rels', 'word/document.xml', 'word/_rels/document.xml.rels', 'word/styles.xml', 'word/numbering.xml']) {
|
|
22
|
+
assert.ok(names.includes(p), p);
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
test('sections come in the document order of the spec', () => {
|
|
27
|
+
const { text } = built();
|
|
28
|
+
const order = ['Riverside Bakery — Scope draft', 'Sources', 'Problems we heard', 'Scope', 'Exclusions',
|
|
29
|
+
'System 1: Orders', 'System 2: Stock', 'Assumptions', 'Questions for the client'];
|
|
30
|
+
let at = -1;
|
|
31
|
+
for (const h of order) {
|
|
32
|
+
const i = text.indexOf(h, at + 1);
|
|
33
|
+
assert.ok(i > at, `${h} missing or out of order`);
|
|
34
|
+
at = i;
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
test('step lines are table boxes', () => {
|
|
39
|
+
const { text, xml } = built();
|
|
40
|
+
assert.match(text, /Main workflow Order In → Bake → Pack → Courier Handoff/);
|
|
41
|
+
assert.match(text, /Custom cake: starts at Order In, rejoins at Bake, ~30% of orders Quote → Confirm Design/);
|
|
42
|
+
assert.equal((xml.match(/<w:tcBorders>/g) ?? []).length, 6, 'one bordered cell per step');
|
|
43
|
+
const long = built((d) => {
|
|
44
|
+
d.systems[0].workflows = [{ kind: 'side', steps: ['A1', 'B2', 'C3', 'D4', 'E5', 'F6', 'G7'], returnsTo: 'Order In', source: 'C1' }];
|
|
45
|
+
});
|
|
46
|
+
assert.match(long.text, /Side path, back to Order In A1 → B2 → C3 → D4 → E5 F6 → G7/);
|
|
47
|
+
const flow = long.xml.split('Side path, back to Order In')[1].split('</w:tbl>')[0];
|
|
48
|
+
assert.equal((flow.match(/<w:cantSplit\/>/g) ?? []).length, 2, '7 steps wrap onto 2 rows');
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test('tables carry their columns and rows', () => {
|
|
52
|
+
const { text } = built();
|
|
53
|
+
assert.match(text, /Feature What it does From Order board Shows every order/);
|
|
54
|
+
assert.match(text, /Exclusion Reason From Delivery routes Owned by someone else C1/);
|
|
55
|
+
assert.match(text, /Question Why it matters If no answer, assume About Last time you ran out of flour/);
|
|
56
|
+
assert.match(text, /"Last month we ran out twice on a Saturday and had to close the cake counter by noon\." \(E1\)/);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
test('empty sections say None', () => {
|
|
60
|
+
const { text } = built((d) => { d.scope.exclusions = []; d.assumptions = []; d.systems[1].features = []; });
|
|
61
|
+
assert.match(text, /Exclusions None\./);
|
|
62
|
+
assert.match(text, /System 2: Stock Keeps flour on hand for weekend baking; closes P1 None\./);
|
|
63
|
+
assert.match(text, /Assumptions None\./);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
test('special characters are escaped', () => {
|
|
67
|
+
const { xml } = built((d) => { d.client = 'Bread & <Butter>\u0001'; });
|
|
68
|
+
assert.match(xml, /Bread & <Butter> — Scope draft/);
|
|
69
|
+
assert.doesNotMatch(xml, /\u0001/);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
test('wrong arguments print usage and exit 2', () => {
|
|
73
|
+
const r = py('build_docx.py', ['--draft']);
|
|
74
|
+
assert.equal(r.code, 2);
|
|
75
|
+
assert.match(r.err, /usage: build_docx\.py --draft <draft\.json> --out <draft-scope\.docx>/);
|
|
76
|
+
});
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { test } from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import { rmSync, writeFileSync } from 'node:fs';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
import { check, stage } from './helpers.mjs';
|
|
6
|
+
|
|
7
|
+
const quote = (d) => d.problems[1].quotes[0];
|
|
8
|
+
|
|
9
|
+
test('a reworded quote is reported with the closest source sentence', () => {
|
|
10
|
+
const r = check(stage((d) => { quote(d).text = 'When a ticket is lost the customer calls us.'; }));
|
|
11
|
+
assert.equal(r.code, 1);
|
|
12
|
+
assert.match(r.err, /^problems\[1\]\.quotes\[0\]: not word for word in C1; closest: "Dana: When a ticket gets lost the customer calls us and we have no idea where the cake is\."$/m);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
test('normalised quotes match: line breaks, extra spaces, part of a sentence', () => {
|
|
16
|
+
const r = check(stage((d) => {
|
|
17
|
+
quote(d).text = 'When a ticket gets lost the customer\ncalls us and we have no idea where the cake is.';
|
|
18
|
+
d.problems[0].quotes[0].text = 'Last month we ran out twice on a Saturday';
|
|
19
|
+
}));
|
|
20
|
+
assert.equal(r.code, 0, r.err);
|
|
21
|
+
const c = check(stage((d) => { quote(d).text = 'the customer calls us'; }));
|
|
22
|
+
assert.equal(c.code, 0, c.err);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
test('a missing source file is reported once', () => {
|
|
26
|
+
const dir = stage();
|
|
27
|
+
rmSync(join(dir, 'sources', 'C1.txt'));
|
|
28
|
+
const r = check(dir);
|
|
29
|
+
assert.equal(r.code, 1);
|
|
30
|
+
assert.match(r.err, /^sources: C1 file sources\/C1\.txt not found$/m);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test('a problem no feature or question points at is reported', () => {
|
|
34
|
+
const r = check(stage((d) => {
|
|
35
|
+
d.problems.push({ id: 'P3', text: 'We cannot see which cakes are custom', quotes: [{ source: 'C1', text: 'About 30% of orders are custom cakes.' }] });
|
|
36
|
+
}));
|
|
37
|
+
assert.equal(r.code, 1);
|
|
38
|
+
assert.match(r.err, /^P3: no feature or client question points at it$/m);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test('a client question alone covers a problem', () => {
|
|
42
|
+
const r = check(stage((d) => {
|
|
43
|
+
d.problems.push({ id: 'P3', text: 'We cannot see which cakes are custom', quotes: [{ source: 'C1', text: 'About 30% of orders are custom cakes.' }] });
|
|
44
|
+
d.questions.push({ text: 'Last time a custom cake was late, where did it wait?', why: 'Shapes the custom-cake steps', assume: 'Same steps as other orders', refs: ['P3'] });
|
|
45
|
+
}));
|
|
46
|
+
assert.equal(r.code, 0, r.err);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test('limits: 7 problems, 9 assumptions, a 6-word step, 1- and 7-word feature names', () => {
|
|
50
|
+
const r = check(stage((d) => {
|
|
51
|
+
for (let n = 3; n <= 7; n++) d.problems.push({ id: `P${n}`, text: 'x', quotes: [quote(d)] });
|
|
52
|
+
d.questions[0].refs = d.problems.map((p) => p.id);
|
|
53
|
+
d.assumptions = Array.from({ length: 9 }, () => d.assumptions[0]);
|
|
54
|
+
d.systems[0].workflows[0].steps[0] = 'Take the order in from WhatsApp';
|
|
55
|
+
d.systems[0].features[0].name = 'Board';
|
|
56
|
+
d.systems[1].features[0].name = 'Alert for flour when it drops low';
|
|
57
|
+
}));
|
|
58
|
+
assert.equal(r.code, 1);
|
|
59
|
+
assert.match(r.err, /^problems: 7, at most 6$/m);
|
|
60
|
+
assert.match(r.err, /^assumptions: 9, at most 8$/m);
|
|
61
|
+
assert.match(r.err, /^systems\[0\]\.workflows\[0\]: step "Take the order in from WhatsApp" has 6 words, at most 5$/m);
|
|
62
|
+
assert.match(r.err, /^systems\[0\]\.features\[0\]: name "Board" has 1 words, 2 to 6$/m);
|
|
63
|
+
assert.match(r.err, /^systems\[1\]\.features\[0\]: name "Alert for flour when it drops low" has 7 words, 2 to 6$/m);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
test('no problems at all is reported', () => {
|
|
67
|
+
const r = check(stage((d) => { d.problems = []; d.systems.forEach((s) => { s.problem = 'P1'; s.features = []; }); d.assumptions = []; d.questions = []; }));
|
|
68
|
+
assert.equal(r.code, 1);
|
|
69
|
+
assert.match(r.err, /^problems: 0, at least 1$/m);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
test('a banned word outside quotes is reported with its place', () => {
|
|
73
|
+
const r = check(stage((d) => {
|
|
74
|
+
d.systems[0].purpose = 'A seamless way to track orders; closes P2';
|
|
75
|
+
d.questions[0].assume = 'Some bags left';
|
|
76
|
+
}));
|
|
77
|
+
assert.equal(r.code, 1);
|
|
78
|
+
assert.match(r.err, /^systems\[0\]\.purpose: vague word "seamless"$/m);
|
|
79
|
+
assert.match(r.err, /^questions\[0\]\.assume: vague word "some"$/m);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
test('vague word inside quotes is allowed', () => {
|
|
83
|
+
const r = check(stage((d) => {
|
|
84
|
+
d.questions[0].text = 'You wrote "deliveries must be fast": by what time of day?';
|
|
85
|
+
d.questions[0].why = 'Sets the promise in “quick” terms';
|
|
86
|
+
}));
|
|
87
|
+
assert.equal(r.code, 0, r.err);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
test('banned words match whole words only', () => {
|
|
91
|
+
const r = check(stage((d) => { d.systems[1].purpose = 'Keeps flour on hand for breakfast baking; closes P1'; }));
|
|
92
|
+
assert.equal(r.code, 0, r.err);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
function withNote(text, quotes) {
|
|
96
|
+
const dir = stage((d) => {
|
|
97
|
+
d.sources.push({ id: 'N1', kind: 'note', date: '2026-09-12', who: 'Dana Lee — reply', file: 'sources/N1.txt' });
|
|
98
|
+
d.problems[0].quotes.push(...quotes.map((q) => ({ source: 'N1', text: q })));
|
|
99
|
+
});
|
|
100
|
+
writeFileSync(join(dir, 'sources', 'N1.txt'), text);
|
|
101
|
+
return check(dir);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
test('reply markers, dashes, case and wrapping quote marks still match', () => {
|
|
105
|
+
const r = withNote('Hi,\n> We need the orders\n> to arrive by 9am.\nThe oven broke — again.\n',
|
|
106
|
+
['we need the orders to arrive by 9am', '“the oven broke - again”']);
|
|
107
|
+
assert.equal(r.code, 0, r.err);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
test('a quote hint never carries a reply marker', () => {
|
|
111
|
+
const r = withNote('Hi,\n> We need the orders to arrive by 9am.\n', ['we need lorries by 9am']);
|
|
112
|
+
assert.equal(r.code, 1);
|
|
113
|
+
assert.match(r.err, /closest: "We need the orders to arrive by 9am\."$/m);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
test('a vague word in single quotes is allowed, an apostrophe is not a quote', () => {
|
|
117
|
+
const ok = check(stage((d) => {
|
|
118
|
+
d.questions[0].text = "You wrote 'fast': by what time of day?";
|
|
119
|
+
d.questions[0].why = 'Sets the ‘quick’ promise';
|
|
120
|
+
}));
|
|
121
|
+
assert.equal(ok.code, 0, ok.err);
|
|
122
|
+
const bad = check(stage((d) => { d.questions[0].assume = "Dana's cakes go out fast"; }));
|
|
123
|
+
assert.match(bad.err, /^questions\[0\]\.assume: vague word "fast"$/m);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
test('a workflow with no steps and a problem with no quote are reported', () => {
|
|
127
|
+
const r = check(stage((d) => { d.systems[0].workflows[0].steps = []; d.problems[1].quotes = []; }));
|
|
128
|
+
assert.equal(r.code, 1);
|
|
129
|
+
assert.match(r.err, /^systems\[0\]\.workflows\[0\]: no steps$/m);
|
|
130
|
+
assert.match(r.err, /^P2: no quote$/m);
|
|
131
|
+
});
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { test } from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import { writeFileSync } from 'node:fs';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
import { check, py, stage } from './helpers.mjs';
|
|
6
|
+
|
|
7
|
+
test('the pass fixture is clean', () => {
|
|
8
|
+
const r = check(stage());
|
|
9
|
+
assert.equal(r.code, 0, r.err);
|
|
10
|
+
assert.match(r.out, /^draft clean$/m);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
test('wrong arguments print usage and exit 2', () => {
|
|
14
|
+
const r = py('check.py', ['--nope']);
|
|
15
|
+
assert.equal(r.code, 2);
|
|
16
|
+
assert.match(r.err, /usage: check\.py --draft <draft\.json>/);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
test('a file that is not JSON exits 1', () => {
|
|
20
|
+
const dir = stage();
|
|
21
|
+
writeFileSync(join(dir, 'draft.json'), '{ nope');
|
|
22
|
+
const r = check(dir);
|
|
23
|
+
assert.equal(r.code, 1);
|
|
24
|
+
assert.match(r.err, /draft\.json: /);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
test('missing or mistyped fields are named with their place', () => {
|
|
28
|
+
const r = check(stage((d) => { delete d.client; }));
|
|
29
|
+
assert.equal(r.code, 1);
|
|
30
|
+
assert.match(r.err, /^draft: client missing or not str$/m);
|
|
31
|
+
const f = check(stage((d) => { delete d.systems[0].features[0].does; }));
|
|
32
|
+
assert.match(f.err, /^systems\[0\]\.features\[0\]: does missing or not str$/m);
|
|
33
|
+
const q = check(stage((d) => { d.questions[0].refs = 'P1'; }));
|
|
34
|
+
assert.match(q.err, /^questions\[0\]: refs missing or not list$/m);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test('ids and kinds outside their lists are reported', () => {
|
|
38
|
+
const r = check(stage((d) => {
|
|
39
|
+
d.sources[0].kind = 'fax';
|
|
40
|
+
d.problems[0].id = 'Problem1';
|
|
41
|
+
d.systems[0].workflows[0].kind = 'loop';
|
|
42
|
+
d.scope.exclusions[0].reason = 'nope';
|
|
43
|
+
}));
|
|
44
|
+
assert.equal(r.code, 1);
|
|
45
|
+
assert.match(r.err, /^sources: E1 kind fax is not email, call or note$/m);
|
|
46
|
+
assert.match(r.err, /^problems: bad id Problem1$/m);
|
|
47
|
+
assert.match(r.err, /^systems\[0\]\.workflows\[0\]: kind loop is not main, side or sub$/m);
|
|
48
|
+
assert.match(r.err, /^scope\.exclusions\[0\]: reason nope is not owned-elsewhere, later-phase or no-detail$/m);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test('references to unknown sources, problems and features are reported', () => {
|
|
52
|
+
const r = check(stage((d) => {
|
|
53
|
+
d.systems[0].features[0].source = 'E9';
|
|
54
|
+
d.systems[1].problem = 'P7';
|
|
55
|
+
d.assumptions[0].feature = 'Nope';
|
|
56
|
+
d.questions[0].refs = ['P1', 'X3'];
|
|
57
|
+
}));
|
|
58
|
+
assert.equal(r.code, 1);
|
|
59
|
+
assert.match(r.err, /^systems\[0\]\.features\[0\]: unknown source E9$/m);
|
|
60
|
+
assert.match(r.err, /^systems\[1\]: unknown problem P7$/m);
|
|
61
|
+
assert.match(r.err, /^assumptions\[0\]: unknown feature Nope$/m);
|
|
62
|
+
assert.match(r.err, /^questions\[0\]: unknown ref X3$/m);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
test('duplicate source and problem ids are reported', () => {
|
|
66
|
+
const r = check(stage((d) => { d.sources[1].id = 'E1'; d.problems[1].id = 'P1'; }));
|
|
67
|
+
assert.equal(r.code, 1);
|
|
68
|
+
assert.match(r.err, /^sources: duplicate id E1$/m);
|
|
69
|
+
assert.match(r.err, /^problems: duplicate id P1$/m);
|
|
70
|
+
});
|