sdtk-spec-kit 0.10.0 → 0.11.0
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 +1 -1
- package/assets/manifest/toolkit-bundle.manifest.json +193 -33
- package/assets/manifest/toolkit-bundle.sha256.txt +47 -15
- package/assets/toolkit/toolkit/AGENTS.md +2 -1
- package/assets/toolkit/toolkit/SDTK_TOOLKIT.md +5 -1
- package/assets/toolkit/toolkit/runtimes/claude/CLAUDE_TEMPLATE.md +4 -0
- package/assets/toolkit/toolkit/scripts/install-claude-skills.ps1 +18 -0
- package/assets/toolkit/toolkit/scripts/install-codex-skills.ps1 +1 -0
- package/assets/toolkit/toolkit/skills/sdtk-arch/SKILL.md +1 -1
- package/assets/toolkit/toolkit/skills/sdtk-ba/SKILL.md +1 -1
- package/assets/toolkit/toolkit/skills/sdtk-customer-qa-sheet/SKILL.md +117 -0
- package/assets/toolkit/toolkit/skills/sdtk-customer-qa-sheet/references/PROFILE_TEMPLATE.md +60 -0
- package/assets/toolkit/toolkit/skills/sdtk-customer-qa-sheet/scripts/oq_sync.py +349 -0
- package/assets/toolkit/toolkit/skills/sdtk-customer-qa-sheet/scripts/test_oq_sync.py +175 -0
- package/assets/toolkit/toolkit/skills/sdtk-db-design/SKILL.md +130 -0
- package/assets/toolkit/toolkit/skills/sdtk-db-design/references/REVIEW_PROCESS.md +82 -0
- package/assets/toolkit/toolkit/skills/sdtk-screen-design-xlsx/SKILL.md +104 -0
- package/assets/toolkit/toolkit/skills/sdtk-screen-design-xlsx/references/REVIEW_AND_MISTAKES.md +63 -0
- package/assets/toolkit/toolkit/skills/sdtk-screen-design-xlsx/references/SCR01.json +46 -0
- package/assets/toolkit/toolkit/skills/sdtk-screen-design-xlsx/references/SCR01.png +0 -0
- package/assets/toolkit/toolkit/skills/sdtk-screen-design-xlsx/references/SPEC_SCHEMA.md +208 -0
- package/assets/toolkit/toolkit/skills/sdtk-screen-design-xlsx/references/example_spec.yaml +115 -0
- package/assets/toolkit/toolkit/skills/sdtk-screen-design-xlsx/scripts/build_design_xlsx.py +550 -0
- package/assets/toolkit/toolkit/skills/sdtk-screen-design-xlsx/scripts/design_spec.py +305 -0
- package/assets/toolkit/toolkit/skills/sdtk-screen-design-xlsx/scripts/export_preview.py +111 -0
- package/assets/toolkit/toolkit/skills/sdtk-screen-design-xlsx/scripts/export_spec_md.py +181 -0
- package/assets/toolkit/toolkit/skills/sdtk-screen-design-xlsx/scripts/make_template.py +113 -0
- package/assets/toolkit/toolkit/skills/sdtk-screen-design-xlsx/scripts/test_screen_design.py +198 -0
- package/assets/toolkit/toolkit/skills/sdtk-screen-design-xlsx/scripts/uia_dump.py +64 -0
- package/assets/toolkit/toolkit/skills/sdtk-screen-design-xlsx/scripts/validate_spec.py +260 -0
- package/assets/toolkit/toolkit/skills/sdtk-session-handoff/SKILL.md +76 -0
- package/assets/toolkit/toolkit/skills/sdtk-session-handoff/references/HANDOFF_TEMPLATE.md +63 -0
- package/assets/toolkit/toolkit/skills/sdtk-session-handoff/references/MOVING_A_PROJECT.md +18 -0
- package/assets/toolkit/toolkit/skills/sdtk-session-handoff/scripts/dirty_files.py +133 -0
- package/assets/toolkit/toolkit/skills/sdtk-session-handoff/scripts/test_dirty_files.py +94 -0
- package/assets/toolkit/toolkit/skills/sdtk-xlsx-safe-edit/SKILL.md +4 -1
- package/assets/toolkit/toolkit/skills/sdtk-xlsx-safe-edit/scripts/test_metadata.py +76 -0
- package/assets/toolkit/toolkit/skills/sdtk-xlsx-safe-edit/scripts/xlsx_xml_edit.py +65 -1
- package/assets/toolkit/toolkit/skills/skills.catalog.yaml +96 -0
- package/assets/toolkit/toolkit/skills-claude/arch/SKILL.md +1 -1
- package/assets/toolkit/toolkit/skills-claude/ba/SKILL.md +1 -1
- package/assets/toolkit/toolkit/skills-claude/customer-qa-sheet/SKILL.md +115 -0
- package/assets/toolkit/toolkit/skills-claude/db-design/SKILL.md +128 -0
- package/assets/toolkit/toolkit/skills-claude/screen-design-xlsx/SKILL.md +101 -0
- package/assets/toolkit/toolkit/skills-claude/session-handoff/SKILL.md +74 -0
- package/assets/toolkit/toolkit/skills-claude/xlsx-safe-edit/SKILL.md +4 -1
- package/assets/toolkit/toolkit/templates/README.md +3 -0
- package/assets/toolkit/toolkit/templates/docs/database/DATABASE_SPEC_TEMPLATE.md +14 -0
- package/assets/toolkit/toolkit/templates/screen-design-xlsx/ja-default/TEMPLATE.md +247 -0
- package/assets/toolkit/toolkit/templates/screen-design-xlsx/ja-default/template.xlsx +0 -0
- package/package.json +1 -1
- package/src/lib/scope.js +4 -4
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""Derive a blank template.xlsx for a template set from a correctly-formatted 画面設計書 workbook.
|
|
3
|
+
|
|
4
|
+
Only needed when the house format itself changes (or for a customer's own set under
|
|
5
|
+
docs/templates/screen-design-xlsx/<set>/):
|
|
6
|
+
|
|
7
|
+
python make_template.py --from "docs/screen_design/<design document>.xlsx" --out docs/templates/screen-design-xlsx/<set>/template.xlsx
|
|
8
|
+
|
|
9
|
+
Then run sdtk-xlsx-safe-edit's `xlsx_xml_edit.py scan-metadata <out> --name <customer> ...`: a workbook derived from
|
|
10
|
+
real work carries its author, saved path, external links and defined names until they are removed.
|
|
11
|
+
|
|
12
|
+
Keeps: the five standard sheets, their grid/column widths/styles/page setup, and exactly one
|
|
13
|
+
empty 40-row block (rows 1..42) on each block sheet. Removes: all content, all drawings,
|
|
14
|
+
all extra sheets.
|
|
15
|
+
"""
|
|
16
|
+
from __future__ import annotations
|
|
17
|
+
|
|
18
|
+
import argparse
|
|
19
|
+
import os
|
|
20
|
+
import shutil
|
|
21
|
+
import sys
|
|
22
|
+
|
|
23
|
+
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
24
|
+
from design_spec import ALL_SHEETS, force_utf8_stdio # noqa: E402
|
|
25
|
+
|
|
26
|
+
try:
|
|
27
|
+
import win32com.client as win32
|
|
28
|
+
except ImportError: # pragma: no cover
|
|
29
|
+
raise SystemExit("pywin32 is required: python -m pip install pywin32")
|
|
30
|
+
|
|
31
|
+
BLOCK_ROWS = 40
|
|
32
|
+
GRID_COLS = 80
|
|
33
|
+
xlCellTypeConstants = 2
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def clear_values(ws, r1, c1, r2, c2):
|
|
37
|
+
"""Blank every constant in the range, keeping formats and merges.
|
|
38
|
+
|
|
39
|
+
Range.ClearContents refuses to touch a range that only partly covers a merged cell,
|
|
40
|
+
so clear each merged area through its anchor instead.
|
|
41
|
+
"""
|
|
42
|
+
rng = ws.Range(ws.Cells(r1, c1), ws.Cells(r2, c2))
|
|
43
|
+
try:
|
|
44
|
+
used = rng.SpecialCells(xlCellTypeConstants)
|
|
45
|
+
except Exception:
|
|
46
|
+
return # nothing but blanks/formats
|
|
47
|
+
for area in used.Areas:
|
|
48
|
+
for cell in area.Cells:
|
|
49
|
+
cell.MergeArea.Cells(1, 1).Value = None
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def main() -> int:
|
|
53
|
+
force_utf8_stdio()
|
|
54
|
+
ap = argparse.ArgumentParser()
|
|
55
|
+
ap.add_argument("--from", dest="src", required=True)
|
|
56
|
+
ap.add_argument("--out", required=True, help="template.xlsx inside a template set folder")
|
|
57
|
+
args = ap.parse_args()
|
|
58
|
+
|
|
59
|
+
src, out = os.path.abspath(args.src), os.path.abspath(args.out)
|
|
60
|
+
os.makedirs(os.path.dirname(out), exist_ok=True)
|
|
61
|
+
shutil.copyfile(src, out)
|
|
62
|
+
|
|
63
|
+
xl = win32.DispatchEx("Excel.Application") # a private instance, never the person's Excel
|
|
64
|
+
xl.Visible = False
|
|
65
|
+
xl.DisplayAlerts = False
|
|
66
|
+
wb = xl.Workbooks.Open(out, UpdateLinks=0)
|
|
67
|
+
try:
|
|
68
|
+
for ws in list(wb.Worksheets):
|
|
69
|
+
if ws.Name not in ALL_SHEETS:
|
|
70
|
+
ws.Delete()
|
|
71
|
+
|
|
72
|
+
for name in ("画面流れ", "処理"):
|
|
73
|
+
ws = wb.Worksheets(name)
|
|
74
|
+
for sh in list(ws.Shapes):
|
|
75
|
+
sh.Delete()
|
|
76
|
+
# keep rows 1..42 as the block template, drop everything after it
|
|
77
|
+
ws.Rows("%d:%d" % (BLOCK_ROWS + 3, 2000)).Delete()
|
|
78
|
+
ws.ResetAllPageBreaks()
|
|
79
|
+
# clear the values in the template block, keep every format and merge
|
|
80
|
+
for ref in ("A1", "Z1", "Z2", "AO2", "AU1", "AU2", "BD1", "BD2"):
|
|
81
|
+
ws.Range(ref).MergeArea.Cells(1, 1).Value = None
|
|
82
|
+
clear_values(ws, 3, 5, 4, GRID_COLS)
|
|
83
|
+
clear_values(ws, 5, 1, BLOCK_ROWS + 2, GRID_COLS)
|
|
84
|
+
# restore the block-header labels the renderer does not write
|
|
85
|
+
ws.Range("I3").Value = "画面名"
|
|
86
|
+
ws.Range("W3").Value = "機能概要"
|
|
87
|
+
ws.Range("A3").Value = "画面ID" if name == "画面流れ" else "処理番号"
|
|
88
|
+
if name == "画面流れ": # right-page UI item table header
|
|
89
|
+
for col, label in (("BK", "項目名"), ("BL", "部品の種類"), ("BM", "属性"),
|
|
90
|
+
("BN", "DBカラム"), ("BO", "桁数"), ("BP", "初期値"),
|
|
91
|
+
("BQ", "必須"), ("BR", "特記事項")):
|
|
92
|
+
ws.Range(col + "3").Value = label
|
|
93
|
+
|
|
94
|
+
wb.Worksheets("改訂記事").Range("A5:H2000").Clear()
|
|
95
|
+
wb.Worksheets("機能概要").Range("A1:H2000").Clear()
|
|
96
|
+
cover = wb.Worksheets("表紙")
|
|
97
|
+
for sh in list(cover.Shapes):
|
|
98
|
+
sh.Delete()
|
|
99
|
+
cover.Range("H9").MergeArea.Cells(1, 1).Value = None
|
|
100
|
+
cover.Range("U37").MergeArea.Cells(1, 1).Value = None
|
|
101
|
+
|
|
102
|
+
wb.Worksheets(ALL_SHEETS[0]).Activate()
|
|
103
|
+
wb.Save()
|
|
104
|
+
finally:
|
|
105
|
+
wb.Close(False) # saved above on success only
|
|
106
|
+
xl.Quit()
|
|
107
|
+
|
|
108
|
+
print("template written: %s (%.0f KB)" % (out, os.path.getsize(out) / 1024))
|
|
109
|
+
return 0
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
if __name__ == "__main__":
|
|
113
|
+
sys.exit(main())
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""Tests for the parts of sdtk-screen-design-xlsx that run without Excel: spec loading, template-set lookup,
|
|
3
|
+
UI Automation markers, the render plan (final mode / hand edits / --sheets), the validator and the Markdown export.
|
|
4
|
+
The COM renderer itself needs Windows + Excel and is checked by hand (see the skill's pressure-test record)."""
|
|
5
|
+
from __future__ import annotations
|
|
6
|
+
|
|
7
|
+
import copy
|
|
8
|
+
import json
|
|
9
|
+
import os
|
|
10
|
+
import re
|
|
11
|
+
import shutil
|
|
12
|
+
import subprocess
|
|
13
|
+
import sys
|
|
14
|
+
import tempfile
|
|
15
|
+
import unittest
|
|
16
|
+
|
|
17
|
+
HERE = os.path.dirname(os.path.abspath(__file__))
|
|
18
|
+
SKILL = os.path.dirname(HERE)
|
|
19
|
+
EXAMPLE = os.path.join(SKILL, "references", "example_spec.yaml")
|
|
20
|
+
sys.path.insert(0, HERE)
|
|
21
|
+
|
|
22
|
+
try:
|
|
23
|
+
import yaml
|
|
24
|
+
import design_spec as ds
|
|
25
|
+
HAVE_YAML = True
|
|
26
|
+
except (ImportError, SystemExit):
|
|
27
|
+
HAVE_YAML = False
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def run(script, *args):
|
|
31
|
+
return subprocess.run([sys.executable, os.path.join(HERE, script), *args], capture_output=True, text=True,
|
|
32
|
+
encoding="utf-8", check=False)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
@unittest.skipUnless(HAVE_YAML, "PyYAML not installed")
|
|
36
|
+
class SpecTests(unittest.TestCase):
|
|
37
|
+
def setUp(self):
|
|
38
|
+
self.tmp = tempfile.mkdtemp()
|
|
39
|
+
for name in os.listdir(os.path.dirname(EXAMPLE)):
|
|
40
|
+
if name.endswith((".yaml", ".png", ".json")):
|
|
41
|
+
shutil.copy(os.path.join(os.path.dirname(EXAMPLE), name), self.tmp)
|
|
42
|
+
self.spec_path = os.path.join(self.tmp, "example_spec.yaml")
|
|
43
|
+
with open(self.spec_path, encoding="utf-8") as f:
|
|
44
|
+
self.raw = yaml.safe_load(f)
|
|
45
|
+
|
|
46
|
+
def tearDown(self):
|
|
47
|
+
shutil.rmtree(self.tmp, ignore_errors=True)
|
|
48
|
+
|
|
49
|
+
def write(self, data, name="spec.yaml"):
|
|
50
|
+
path = os.path.join(self.tmp, name)
|
|
51
|
+
with open(path, "w", encoding="utf-8") as f:
|
|
52
|
+
yaml.safe_dump(data, f, allow_unicode=True, sort_keys=False)
|
|
53
|
+
return path
|
|
54
|
+
|
|
55
|
+
def validate(self, data):
|
|
56
|
+
r = run("validate_spec.py", "--spec", self.write(data))
|
|
57
|
+
return r.returncode, r.stdout
|
|
58
|
+
|
|
59
|
+
# ---- example + template set
|
|
60
|
+
def test_example_validates_clean_and_finds_the_shipped_template(self):
|
|
61
|
+
code, out = self.validate(self.raw)
|
|
62
|
+
self.assertEqual(code, 0, out)
|
|
63
|
+
self.assertIn("0 error(s), 0 warning(s)", out)
|
|
64
|
+
spec = ds.load_spec(self.spec_path)
|
|
65
|
+
self.assertTrue(spec["workbook"]["template"].endswith(os.path.join("ja-default", "template.xlsx")))
|
|
66
|
+
self.assertTrue(os.path.isfile(spec["workbook"]["template"]))
|
|
67
|
+
|
|
68
|
+
def test_project_template_set_wins_over_the_shipped_one(self):
|
|
69
|
+
own = os.path.join(self.tmp, "docs", "templates", "screen-design-xlsx", "ja-default")
|
|
70
|
+
os.makedirs(own)
|
|
71
|
+
with open(os.path.join(own, "TEMPLATE.md"), "w", encoding="utf-8") as f:
|
|
72
|
+
f.write('```json config\n{"output_template": "mine.xlsx"}\n```\n')
|
|
73
|
+
cwd = os.getcwd()
|
|
74
|
+
os.chdir(self.tmp)
|
|
75
|
+
try:
|
|
76
|
+
spec = ds.load_spec(self.spec_path)
|
|
77
|
+
finally:
|
|
78
|
+
os.chdir(cwd)
|
|
79
|
+
self.assertEqual(os.path.realpath(spec["workbook"]["template"]), os.path.realpath(os.path.join(own, "mine.xlsx")))
|
|
80
|
+
|
|
81
|
+
# ---- UI Automation markers
|
|
82
|
+
def test_uia_markers_are_fractions_of_the_captured_window(self):
|
|
83
|
+
spec = ds.load_spec(self.spec_path)
|
|
84
|
+
self.assertEqual(spec["screens"][0]["markers"],
|
|
85
|
+
[{"n": 1, "x": 0.2, "y": 0.15}, {"n": 2, "x": 0.4625, "y": 0.15}, {"n": 3, "x": 0.5, "y": 0.57}])
|
|
86
|
+
|
|
87
|
+
def test_uia_marker_problems_are_validation_errors(self):
|
|
88
|
+
data = copy.deepcopy(self.raw)
|
|
89
|
+
data["screens"][0]["uia"]["markers"].append({"n": 4, "id": "NoSuchControl"})
|
|
90
|
+
data["screens"][0]["markers"] = [{"n": 1, "x": 0.1, "y": 0.1}]
|
|
91
|
+
code, out = self.validate(data)
|
|
92
|
+
self.assertEqual(code, 1)
|
|
93
|
+
self.assertIn("0 elements with id 'NoSuchControl'", out)
|
|
94
|
+
self.assertIn("both `markers` and `uia` given", out)
|
|
95
|
+
|
|
96
|
+
# ---- validator additions
|
|
97
|
+
def test_missing_sub_process_and_bad_reference_are_errors(self):
|
|
98
|
+
data = copy.deepcopy(self.raw)
|
|
99
|
+
flow = data["processes"][0]
|
|
100
|
+
flow["nodes"][2]["sub"] = "SCR01-1-9"
|
|
101
|
+
flow["notes"][3]["lines"] = ["SCR09-1-1 を参照"]
|
|
102
|
+
code, out = self.validate(data)
|
|
103
|
+
self.assertEqual(code, 1)
|
|
104
|
+
self.assertIn("points at sub-process SCR01-1-9", out)
|
|
105
|
+
self.assertIn("refers to SCR09-1-1", out)
|
|
106
|
+
|
|
107
|
+
def test_terminating_branch_on_the_last_node_overflows_the_page(self):
|
|
108
|
+
data = copy.deepcopy(self.raw)
|
|
109
|
+
nodes = data["processes"][0]["nodes"]
|
|
110
|
+
box = {"type": "box", "n": "⑥", "text": "x"}
|
|
111
|
+
decision = copy.deepcopy(nodes[1])
|
|
112
|
+
data["processes"][0]["nodes"] = [box, copy.deepcopy(box), copy.deepcopy(box), copy.deepcopy(box),
|
|
113
|
+
copy.deepcopy(box), decision]
|
|
114
|
+
code, out = self.validate(data)
|
|
115
|
+
self.assertEqual(code, 1)
|
|
116
|
+
self.assertIn("falls past the page end", out)
|
|
117
|
+
|
|
118
|
+
def test_remarks_and_screenshot_must_fit_the_page(self):
|
|
119
|
+
data = copy.deepcopy(self.raw)
|
|
120
|
+
data["screens"][0]["remarks"] = [{"text": "・x", "alt": "y"}] * 5
|
|
121
|
+
data["screens"][0]["image_width_pt"] = 900
|
|
122
|
+
code, out = self.validate(data)
|
|
123
|
+
self.assertEqual(code, 1)
|
|
124
|
+
self.assertIn("<備考> needs 11 rows", out)
|
|
125
|
+
self.assertIn("set a smaller image_width_pt", out)
|
|
126
|
+
|
|
127
|
+
# ---- render plan
|
|
128
|
+
def plan(self, **kw):
|
|
129
|
+
return ds.render_plan(ds.load_spec(self.spec_path), **kw)
|
|
130
|
+
|
|
131
|
+
def make_workbook(self):
|
|
132
|
+
spec = ds.load_spec(self.spec_path)
|
|
133
|
+
os.makedirs(os.path.dirname(spec["workbook"]["path"]), exist_ok=True)
|
|
134
|
+
shutil.copy(spec["workbook"]["template"], spec["workbook"]["path"])
|
|
135
|
+
return spec
|
|
136
|
+
|
|
137
|
+
def test_new_workbook_renders_every_sheet(self):
|
|
138
|
+
p = self.plan()
|
|
139
|
+
self.assertTrue(p["from_template"])
|
|
140
|
+
self.assertEqual(p["sheets"], ["表紙", "改訂記事", "機能概要", "画面流れ", "処理"])
|
|
141
|
+
|
|
142
|
+
def test_existing_workbook_needs_sheets(self):
|
|
143
|
+
spec = self.make_workbook()
|
|
144
|
+
ds.write_stamp(spec, ["処理"])
|
|
145
|
+
with self.assertRaisesRegex(SystemExit, "pass --sheets"):
|
|
146
|
+
self.plan()
|
|
147
|
+
self.assertEqual(self.plan(sheets_arg="処理")["sheets"], ["処理"])
|
|
148
|
+
|
|
149
|
+
def test_hand_edited_or_unstamped_workbook_is_refused_without_confirmation(self):
|
|
150
|
+
spec = self.make_workbook()
|
|
151
|
+
with self.assertRaisesRegex(SystemExit, "no render stamp"):
|
|
152
|
+
self.plan(sheets_arg="処理")
|
|
153
|
+
ds.write_stamp(spec, ["処理"])
|
|
154
|
+
with open(spec["workbook"]["path"], "ab") as f:
|
|
155
|
+
f.write(b"\0") # anything that changes the bytes
|
|
156
|
+
with self.assertRaisesRegex(SystemExit, "changed after the last render"):
|
|
157
|
+
self.plan(sheets_arg="処理")
|
|
158
|
+
self.assertEqual(self.plan(sheets_arg="処理", accept_hand_edits=True)["sheets"], ["処理"])
|
|
159
|
+
|
|
160
|
+
def test_final_workbook_is_never_rendered(self):
|
|
161
|
+
self.make_workbook()
|
|
162
|
+
data = copy.deepcopy(self.raw)
|
|
163
|
+
data["workbook"]["final"] = True
|
|
164
|
+
path = self.write(data, "example_spec.yaml")
|
|
165
|
+
with self.assertRaisesRegex(SystemExit, "finalized by hand"):
|
|
166
|
+
ds.render_plan(ds.load_spec(path), sheets_arg="処理", accept_hand_edits=True)
|
|
167
|
+
|
|
168
|
+
def test_unknown_sheet_is_refused_and_out_never_targets_the_workbook(self):
|
|
169
|
+
with self.assertRaisesRegex(SystemExit, "unknown sheet"):
|
|
170
|
+
self.plan(sheets_arg="処理,Nope")
|
|
171
|
+
self.make_workbook()
|
|
172
|
+
p = self.plan(out=os.path.join(self.tmp, "preview.xlsx"))
|
|
173
|
+
self.assertTrue(p["target"].endswith("preview.xlsx"))
|
|
174
|
+
self.assertFalse(p["stamp"])
|
|
175
|
+
|
|
176
|
+
# ---- markdown export
|
|
177
|
+
def test_markdown_export_is_japanese_and_lists_every_block(self):
|
|
178
|
+
r = run("export_spec_md.py", "--spec", self.spec_path)
|
|
179
|
+
self.assertEqual(r.returncode, 0, r.stderr)
|
|
180
|
+
self.assertIn("## シート `処理` の内容", r.stdout)
|
|
181
|
+
self.assertIn("### SCR01-1-1 — 注文を検索する", r.stdout)
|
|
182
|
+
self.assertIsNone(re.search(r"[À-ỹ]", r.stdout)) # no Vietnamese left from the source
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
class ScriptSafetyTests(unittest.TestCase):
|
|
186
|
+
def test_no_script_attaches_to_the_persons_excel_or_saves_with_openpyxl(self):
|
|
187
|
+
for name in os.listdir(HERE):
|
|
188
|
+
if not name.endswith(".py") or name.startswith("test_"):
|
|
189
|
+
continue
|
|
190
|
+
with open(os.path.join(HERE, name), encoding="utf-8") as f:
|
|
191
|
+
code = f.read()
|
|
192
|
+
self.assertIsNone(re.search(r"\bDispatch\(", code), name)
|
|
193
|
+
self.assertIsNone(re.search(r"\.Close\(True\)", code), name)
|
|
194
|
+
self.assertIsNone(re.search(r"import openpyxl|openpyxl\.", code), name)
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
if __name__ == "__main__":
|
|
198
|
+
unittest.main()
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""Screenshot + UI Automation dump of one window, for markers placed by element instead of by eye.
|
|
3
|
+
|
|
4
|
+
python uia_dump.py --title "Settings" --out docs/screen_design/_uia/SCR02 [--inset 8]
|
|
5
|
+
|
|
6
|
+
Writes <out>.png (the window as it is on screen) and <out>.json:
|
|
7
|
+
{"window": {"rect": [l, t, r, b], "inset": 8},
|
|
8
|
+
"elements": [{"automation_id": "...", "name": "...", "control_type": "...", "rect": [l, t, r, b]}, ...]}
|
|
9
|
+
Rectangles are screen coordinates; design_spec.uia_markers() turns them into marker fractions of the image:
|
|
10
|
+
|
|
11
|
+
screens:
|
|
12
|
+
- id: SCR02
|
|
13
|
+
image: _uia/SCR02.png
|
|
14
|
+
uia: {dump: _uia/SCR02.json, markers: [{n: 1, id: AccountLabel}, {n: 2, name: 保存}]}
|
|
15
|
+
|
|
16
|
+
Read-only: it only reads the window. Requires Windows + pywinauto + Pillow. Take the screenshot of the test build
|
|
17
|
+
(code-ui-e2e), not of someone's working app with their data on it.
|
|
18
|
+
"""
|
|
19
|
+
from __future__ import annotations
|
|
20
|
+
|
|
21
|
+
import argparse
|
|
22
|
+
import json
|
|
23
|
+
import sys
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def dump(window, out_base: str, inset: int = 0) -> dict:
|
|
27
|
+
from PIL import ImageGrab
|
|
28
|
+
r = window.rectangle()
|
|
29
|
+
rect = [r.left, r.top, r.right, r.bottom]
|
|
30
|
+
ImageGrab.grab(bbox=(r.left + inset, r.top + inset, r.right - inset, r.bottom - inset),
|
|
31
|
+
all_screens=True).save(out_base + ".png")
|
|
32
|
+
elements = []
|
|
33
|
+
for el in window.descendants():
|
|
34
|
+
info = el.element_info
|
|
35
|
+
try:
|
|
36
|
+
er = el.rectangle()
|
|
37
|
+
except Exception: # elements that vanished while walking the tree
|
|
38
|
+
continue
|
|
39
|
+
if er.width() <= 0 or er.height() <= 0:
|
|
40
|
+
continue
|
|
41
|
+
elements.append({"automation_id": info.automation_id or "", "name": info.name or "",
|
|
42
|
+
"control_type": info.control_type or "", "rect": [er.left, er.top, er.right, er.bottom]})
|
|
43
|
+
data = {"window": {"rect": rect, "inset": inset}, "elements": elements}
|
|
44
|
+
with open(out_base + ".json", "w", encoding="utf-8") as f:
|
|
45
|
+
json.dump(data, f, ensure_ascii=False, indent=1)
|
|
46
|
+
return data
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def main() -> int:
|
|
50
|
+
ap = argparse.ArgumentParser()
|
|
51
|
+
ap.add_argument("--title", required=True, help="window title (regular expression)")
|
|
52
|
+
ap.add_argument("--out", required=True, help="path without extension")
|
|
53
|
+
ap.add_argument("--inset", type=int, default=0, help="pixels trimmed from each edge (rounded corners)")
|
|
54
|
+
args = ap.parse_args()
|
|
55
|
+
from pywinauto import Desktop
|
|
56
|
+
window = Desktop(backend="uia").window(title_re=args.title)
|
|
57
|
+
window.wait("visible", timeout=10)
|
|
58
|
+
data = dump(window, args.out, args.inset)
|
|
59
|
+
print("%s.png + %s.json (%d elements)" % (args.out, args.out, len(data["elements"])))
|
|
60
|
+
return 0
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
if __name__ == "__main__":
|
|
64
|
+
sys.exit(main())
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""Check a design_spec.yaml against the layout budgets of the 画面設計書 format.
|
|
3
|
+
|
|
4
|
+
Catches the failure modes that are invisible in the YAML and silent in Excel:
|
|
5
|
+
text clipped inside a shape, annotation text running off the printed page, and
|
|
6
|
+
blocks that do not fit in one 40-row page.
|
|
7
|
+
|
|
8
|
+
python validate_spec.py --spec docs/screen_design/design_spec.yaml
|
|
9
|
+
|
|
10
|
+
Exits non-zero if any error is found. Warnings do not fail the run.
|
|
11
|
+
"""
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
import argparse
|
|
15
|
+
import math
|
|
16
|
+
import os
|
|
17
|
+
import re
|
|
18
|
+
import struct
|
|
19
|
+
import sys
|
|
20
|
+
|
|
21
|
+
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
22
|
+
from design_spec import (ANN_BUDGET, BOX_CHARS, BOX_LINES, DEC_CHARS, DEC_LINES, # noqa: E402
|
|
23
|
+
DETAIL_NOTE_BUDGET,
|
|
24
|
+
MAX_FLOW_NODES, col_to_index, force_utf8_stdio, fw,
|
|
25
|
+
iter_process_sheets, load_spec)
|
|
26
|
+
|
|
27
|
+
REF_RE = re.compile(r"([A-Z]{2,}\d+(?:-\d+)+)\s*(?:を参照|参照)")
|
|
28
|
+
|
|
29
|
+
errors: list[str] = []
|
|
30
|
+
warnings: list[str] = []
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def err(where: str, msg: str) -> None:
|
|
34
|
+
errors.append("%s: %s" % (where, msg))
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def warn(where: str, msg: str) -> None:
|
|
38
|
+
warnings.append("%s: %s" % (where, msg))
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def check_shape_text(where: str, text: str, max_lines: int, max_chars: int, kind: str) -> None:
|
|
42
|
+
"""Shape text is soft-wrapped by Excel; only the total wrapped height can clip it."""
|
|
43
|
+
lines = (text or "").split("\n")
|
|
44
|
+
wrapped = sum(max(1, math.ceil(fw(ln) / max_chars)) for ln in lines)
|
|
45
|
+
if wrapped > max_lines:
|
|
46
|
+
err(where, "%s renders as %d wrapped lines, only %d fit — the rest is clipped silently"
|
|
47
|
+
% (kind, wrapped, max_lines))
|
|
48
|
+
elif wrapped > len(lines):
|
|
49
|
+
for ln in lines:
|
|
50
|
+
if fw(ln) > max_chars:
|
|
51
|
+
warn(where, "%s line wraps (%.1f > %d fw chars), which usually leaves an "
|
|
52
|
+
"orphan fragment: %r" % (kind, fw(ln), max_chars, ln))
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def check_flow(where: str, blk: dict, block_rows: int) -> None:
|
|
56
|
+
nodes = blk.get("nodes") or []
|
|
57
|
+
if not nodes:
|
|
58
|
+
err(where, "flow block has no nodes")
|
|
59
|
+
if len(nodes) > MAX_FLOW_NODES:
|
|
60
|
+
err(where, "%d main-column nodes, max %d for a %d-row page — split into a sub-process"
|
|
61
|
+
% (len(nodes), MAX_FLOW_NODES, block_rows))
|
|
62
|
+
|
|
63
|
+
marks = []
|
|
64
|
+
prev_branch_terminates = False
|
|
65
|
+
for i, nd in enumerate(nodes):
|
|
66
|
+
w = "%s node %d" % (where, i + 1)
|
|
67
|
+
t = nd.get("type")
|
|
68
|
+
if t not in ("box", "decision"):
|
|
69
|
+
err(w, "unknown node type %r" % (t,))
|
|
70
|
+
continue
|
|
71
|
+
# A terminating branch needs box + gap + ◎ ≈ 6 rows in the side column, but the
|
|
72
|
+
# node pitch is 5. Two decisions in a row therefore overlap: the first branch's
|
|
73
|
+
# terminator is painted over by the second branch's white box and vanishes, and
|
|
74
|
+
# its arrow appears to run into that box instead. Nothing errors at render time.
|
|
75
|
+
if t == "decision" and prev_branch_terminates:
|
|
76
|
+
err(w, "decision directly follows a decision whose branch terminates — the "
|
|
77
|
+
"previous ◎ is hidden behind this branch's box. Put a box node between "
|
|
78
|
+
"them, or merge the two conditions.")
|
|
79
|
+
prev_branch_terminates = (t == "decision"
|
|
80
|
+
and bool((nd.get("branch") or {}).get("terminate")))
|
|
81
|
+
if nd.get("n"):
|
|
82
|
+
marks.append(nd["n"])
|
|
83
|
+
if t == "box":
|
|
84
|
+
check_shape_text(w, nd.get("text", ""), BOX_LINES, BOX_CHARS, "box")
|
|
85
|
+
else:
|
|
86
|
+
check_shape_text(w, nd.get("text", ""), DEC_LINES, DEC_CHARS, "decision")
|
|
87
|
+
br = nd.get("branch")
|
|
88
|
+
if not br:
|
|
89
|
+
err(w, "decision node needs a `branch`")
|
|
90
|
+
else:
|
|
91
|
+
if br.get("n"):
|
|
92
|
+
marks.append(br["n"])
|
|
93
|
+
check_shape_text(w + " branch", br.get("text", ""), BOX_LINES, BOX_CHARS, "box")
|
|
94
|
+
for key, lim in (("label", 8), ("", 0)):
|
|
95
|
+
if key and fw(str(br.get(key, ""))) > lim:
|
|
96
|
+
warn(w, "branch label %r is wide; it may overlap the side box"
|
|
97
|
+
% (br.get(key),))
|
|
98
|
+
if fw(str(nd.get("else_label", ""))) > 8:
|
|
99
|
+
warn(w, "else_label %r is wide; it may collide with the merge connector"
|
|
100
|
+
% (nd.get("else_label"),))
|
|
101
|
+
|
|
102
|
+
# page overflow: the end terminator sits at row 7 + 5 * nodes of the block and needs two rows; a branch that
|
|
103
|
+
# terminates draws its ◎ about eight rows below its node.
|
|
104
|
+
end_row = 7 + len(nodes) * 5 + 2
|
|
105
|
+
if end_row > block_rows - 1:
|
|
106
|
+
err(where, "the flow ends on row %d of a %d-row page — it runs onto the next page" % (end_row, block_rows))
|
|
107
|
+
for i, nd in enumerate(nodes):
|
|
108
|
+
if nd.get("type") == "decision" and (nd.get("branch") or {}).get("terminate"):
|
|
109
|
+
if 7 + i * 5 + 8 > block_rows - 1:
|
|
110
|
+
err("%s node %d" % (where, i + 1), "the terminating branch's ◎ falls past the page end — move the "
|
|
111
|
+
"decision up or let the branch merge back")
|
|
112
|
+
|
|
113
|
+
ac = col_to_index(blk.get("ann_col", "X"))
|
|
114
|
+
budget = ANN_BUDGET.get(ac)
|
|
115
|
+
if budget is None:
|
|
116
|
+
budget = min(ANN_BUDGET.values())
|
|
117
|
+
warn(where, "ann_col %r is not a standard column; assuming a %d-char budget"
|
|
118
|
+
% (blk.get("ann_col"), budget))
|
|
119
|
+
height = 0
|
|
120
|
+
note_marks = []
|
|
121
|
+
for note in blk.get("notes") or []:
|
|
122
|
+
note_marks.append(note.get("mark"))
|
|
123
|
+
lines = note.get("lines") or []
|
|
124
|
+
height += len(lines) + 1
|
|
125
|
+
for ln in lines:
|
|
126
|
+
if fw(ln) > budget:
|
|
127
|
+
err(where, "note %s line %.1f fw chars > %d (runs off the page): %r"
|
|
128
|
+
% (note.get("mark"), fw(ln), budget, ln))
|
|
129
|
+
if height > block_rows - 10:
|
|
130
|
+
err(where, "explanation list needs %d rows, only %d available"
|
|
131
|
+
% (height, block_rows - 10))
|
|
132
|
+
|
|
133
|
+
missing = [m for m in marks if m not in note_marks]
|
|
134
|
+
if missing:
|
|
135
|
+
warn(where, "flowchart markers with no explanation entry: %s" % ", ".join(missing))
|
|
136
|
+
extra = [m for m in note_marks if m not in marks and m != "※"]
|
|
137
|
+
if extra:
|
|
138
|
+
warn(where, "explanation entries with no flowchart marker: %s" % ", ".join(extra))
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
def check_detail(where: str, blk: dict, block_rows: int) -> None:
|
|
142
|
+
if not blk.get("sub_no"):
|
|
143
|
+
err(where, "detail block needs `sub_no`")
|
|
144
|
+
height = 0
|
|
145
|
+
for i, sec in enumerate(blk.get("sections") or []):
|
|
146
|
+
w = "%s section %d (%s)" % (where, i + 1, sec.get("head"))
|
|
147
|
+
if not sec.get("head"):
|
|
148
|
+
err(w, "section needs a `head`")
|
|
149
|
+
height += 1
|
|
150
|
+
cols = sec.get("columns") or []
|
|
151
|
+
rows = sec.get("rows") or []
|
|
152
|
+
if cols:
|
|
153
|
+
last = cols[-1]
|
|
154
|
+
end = col_to_index(last["col"]) + int(last["span"]) - 1
|
|
155
|
+
if end > 61:
|
|
156
|
+
err(w, "table ends at column %d, past BI (61) — it will be cut off when printed"
|
|
157
|
+
% end)
|
|
158
|
+
for j, row in enumerate(rows):
|
|
159
|
+
if len(row) != len(cols):
|
|
160
|
+
err(w, "row %d has %d cells but the table has %d columns"
|
|
161
|
+
% (j + 1, len(row), len(cols)))
|
|
162
|
+
height += 1 + len(rows)
|
|
163
|
+
elif rows:
|
|
164
|
+
err(w, "`rows` given without `columns`")
|
|
165
|
+
for j, line in enumerate(sec.get("notes") or []):
|
|
166
|
+
if fw(line) > DETAIL_NOTE_BUDGET:
|
|
167
|
+
err(w, "note %d is %.1f fw chars > %d — it runs past column BI and is cut "
|
|
168
|
+
"off mid-sentence when printed: %r"
|
|
169
|
+
% (j + 1, fw(line), DETAIL_NOTE_BUDGET, line[:40] + "…"))
|
|
170
|
+
height += len(sec.get("notes") or []) + 1
|
|
171
|
+
if height > block_rows - 6:
|
|
172
|
+
err(where, "detail page needs %d rows, only %d available" % (height, block_rows - 6))
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
def check_screen(where: str, scr: dict, block_rows: int) -> None:
|
|
176
|
+
for key in ("id", "name"):
|
|
177
|
+
if not scr.get(key):
|
|
178
|
+
err(where, "screen needs `%s`" % key)
|
|
179
|
+
img = scr.get("image")
|
|
180
|
+
if img and not os.path.exists(img):
|
|
181
|
+
err(where, "image not found: %s" % img)
|
|
182
|
+
items = scr.get("items") or []
|
|
183
|
+
if len(items) > block_rows - 3:
|
|
184
|
+
err(where, "%d UI items, only %d table rows fit on the page"
|
|
185
|
+
% (len(items), block_rows - 3))
|
|
186
|
+
for problem in scr.get("_problems") or []:
|
|
187
|
+
err(where, problem)
|
|
188
|
+
image_rows = 0
|
|
189
|
+
if img and os.path.exists(img) and img.lower().endswith(".png"):
|
|
190
|
+
with open(img, "rb") as f:
|
|
191
|
+
head = f.read(24)
|
|
192
|
+
if head[:8] == b"\x89PNG\r\n\x1a\n":
|
|
193
|
+
w_px, h_px = struct.unpack(">II", head[16:24])
|
|
194
|
+
image_rows = math.ceil(float(scr.get("image_width_pt", 571)) * h_px / w_px / 13.5)
|
|
195
|
+
remarks = scr.get("remarks") or []
|
|
196
|
+
remark_rows = (1 + sum(1 + (1 if r.get("alt") else 0) for r in remarks)) if remarks else 0
|
|
197
|
+
if remark_rows > 10:
|
|
198
|
+
err(where, "<備考> needs %d rows, only 10 fit at the bottom of the page" % remark_rows)
|
|
199
|
+
limit = block_rows - (10 if remarks else 1)
|
|
200
|
+
if image_rows and 2 + image_rows > limit:
|
|
201
|
+
err(where, "the screenshot reaches row %d of the page, past row %d%s — set a smaller image_width_pt"
|
|
202
|
+
% (2 + image_rows, limit, " where <備考> starts" if remarks else ""))
|
|
203
|
+
markers = scr.get("markers") or []
|
|
204
|
+
for m in markers:
|
|
205
|
+
if not (0 <= float(m.get("x", -1)) <= 1 and 0 <= float(m.get("y", -1)) <= 1):
|
|
206
|
+
err(where, "marker %s: x/y must be fractions of the image box (0..1)" % m.get("n"))
|
|
207
|
+
if markers and items and len(markers) != len(items):
|
|
208
|
+
warn(where, "%d markers but %d UI items — they are meant to correspond one-to-one"
|
|
209
|
+
% (len(markers), len(items)))
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
def main() -> int:
|
|
213
|
+
force_utf8_stdio()
|
|
214
|
+
ap = argparse.ArgumentParser()
|
|
215
|
+
ap.add_argument("--spec", required=True)
|
|
216
|
+
args = ap.parse_args()
|
|
217
|
+
|
|
218
|
+
spec = load_spec(args.spec)
|
|
219
|
+
block_rows = spec["workbook"]["block_rows"]
|
|
220
|
+
|
|
221
|
+
sheets = list(iter_process_sheets(spec))
|
|
222
|
+
|
|
223
|
+
# sub-process references resolve across sheets: a flow on 処理 may point at a detail
|
|
224
|
+
# page that lives on a feature sheet.
|
|
225
|
+
subs = {blk["sub_no"] for _, blocks in sheets for blk in blocks if blk.get("sub_no")}
|
|
226
|
+
ids = {blk.get("id") for _, blocks in sheets for blk in blocks if blk.get("id")}
|
|
227
|
+
|
|
228
|
+
for sheet, blocks in sheets:
|
|
229
|
+
for i, blk in enumerate(blocks):
|
|
230
|
+
where = "%s[%d] %s" % (sheet, i, blk.get("sub_no") or blk.get("id") or blk.get("no"))
|
|
231
|
+
kind = blk.get("kind")
|
|
232
|
+
if kind == "flow":
|
|
233
|
+
check_flow(where, blk, block_rows)
|
|
234
|
+
for nd in blk.get("nodes") or []:
|
|
235
|
+
if nd.get("sub") and nd["sub"] not in subs:
|
|
236
|
+
err(where, "node %s points at sub-process %s, which has no detail page"
|
|
237
|
+
% (nd.get("n") or "?", nd["sub"]))
|
|
238
|
+
for note in blk.get("notes") or []:
|
|
239
|
+
for ref in REF_RE.findall(" ".join(note.get("lines") or [])):
|
|
240
|
+
if ref not in subs and ref not in ids:
|
|
241
|
+
err(where, "note %s refers to %s (…を参照), which is neither a detail page nor a block"
|
|
242
|
+
% (note.get("mark"), ref))
|
|
243
|
+
elif kind == "detail":
|
|
244
|
+
check_detail(where, blk, block_rows)
|
|
245
|
+
else:
|
|
246
|
+
err(where, "unknown block kind %r (expected flow|detail)" % (kind,))
|
|
247
|
+
|
|
248
|
+
for i, scr in enumerate(spec.get("screens") or []):
|
|
249
|
+
check_screen("screens[%d] %s" % (i, scr.get("id")), scr, block_rows)
|
|
250
|
+
|
|
251
|
+
for line in warnings:
|
|
252
|
+
print("WARN " + line)
|
|
253
|
+
for line in errors:
|
|
254
|
+
print("ERROR " + line)
|
|
255
|
+
print("\n%d error(s), %d warning(s)" % (len(errors), len(warnings)))
|
|
256
|
+
return 1 if errors else 0
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
if __name__ == "__main__":
|
|
260
|
+
sys.exit(main())
|