arch-insight-cli 0.3.0__tar.gz → 0.4.1__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: arch-insight-cli
3
- Version: 0.3.0
3
+ Version: 0.4.1
4
4
  Summary: Command-line client for ARCH-Insight tasks, factsheets, secrets, and developer platform.
5
5
  Requires-Python: >=3.10
6
6
  Description-Content-Type: text/markdown
@@ -91,6 +91,23 @@ arch project import plan.json
91
91
 
92
92
  See `arch_cli/work.py` for the file format.
93
93
 
94
+ ## Organisation
95
+
96
+ ```sh
97
+ arch org show # name, members, whether Entra sign-in is on
98
+ arch org entra show # the Redirect URI to register in Entra
99
+ ARCH_ENTRA_CLIENT_SECRET=... arch org entra set --tenant-id <Directory ID> --client-id <Application ID>
100
+ ```
101
+
102
+ With Entra sign-in on, members choose "Sign in with your organization" on the
103
+ login screen and type the organisation's name. `--domain` (a domain proven
104
+ under Organization -> Access) also sends that domain's addresses to Entra by
105
+ themselves. The secret is read from `ARCH_ENTRA_CLIENT_SECRET` or asked for,
106
+ never taken as an argument.
107
+
108
+ `arch login` prints the organisation it signed in to. A browser sign-in uses
109
+ the account that browser is signed in to; check it before importing.
110
+
94
111
  ## Marketing e-mail
95
112
 
96
113
  Contact lists drop malformed addresses and reserved domains (`example.com`,
@@ -83,6 +83,23 @@ arch project import plan.json
83
83
 
84
84
  See `arch_cli/work.py` for the file format.
85
85
 
86
+ ## Organisation
87
+
88
+ ```sh
89
+ arch org show # name, members, whether Entra sign-in is on
90
+ arch org entra show # the Redirect URI to register in Entra
91
+ ARCH_ENTRA_CLIENT_SECRET=... arch org entra set --tenant-id <Directory ID> --client-id <Application ID>
92
+ ```
93
+
94
+ With Entra sign-in on, members choose "Sign in with your organization" on the
95
+ login screen and type the organisation's name. `--domain` (a domain proven
96
+ under Organization -> Access) also sends that domain's addresses to Entra by
97
+ themselves. The secret is read from `ARCH_ENTRA_CLIENT_SECRET` or asked for,
98
+ never taken as an argument.
99
+
100
+ `arch login` prints the organisation it signed in to. A browser sign-in uses
101
+ the account that browser is signed in to; check it before importing.
102
+
86
103
  ## Marketing e-mail
87
104
 
88
105
  Contact lists drop malformed addresses and reserved domains (`example.com`,
@@ -1,3 +1,3 @@
1
1
  """ARCH-Insight command-line client."""
2
2
 
3
- __version__ = "0.3.0"
3
+ __version__ = "0.4.1"
@@ -9,6 +9,7 @@ package.
9
9
  from __future__ import annotations
10
10
 
11
11
  import argparse
12
+ import getpass
12
13
  import json
13
14
  import os
14
15
  import secrets
@@ -231,8 +232,13 @@ def login(args):
231
232
  raise CliError(str(exc)) from exc
232
233
  args.token = record["access_token"]
233
234
  me = request(args, "GET", "/api/auth/me")
234
- emit({"signed_in_as": me.get("email"), "org_id": me.get("org_id"),
235
- "roles": me.get("roles"), "stored_in": str(auth.credentials_path())})
235
+ # The organisation by name, not only its id: a browser sign-in reuses
236
+ # whatever account that browser is signed in to, and "org_id": 7 does not
237
+ # tell anyone they are about to import into the wrong organisation.
238
+ org = request(args, "GET", "/api/orgs/me") if me.get("org_id") else {}
239
+ emit({"signed_in_as": me.get("email"), "organization": org.get("name"),
240
+ "org_id": me.get("org_id"), "roles": me.get("roles"),
241
+ "stored_in": str(auth.credentials_path())})
236
242
 
237
243
 
238
244
  def logout(args):
@@ -390,8 +396,42 @@ def campaign_delete(args):
390
396
 
391
397
 
392
398
  # --- organisation (#1072) ---------------------------------------------------------
399
+ ORG_FIELDS = ("id", "name", "website", "industry", "timezone", "subdomain", "member_count")
400
+
401
+
393
402
  def org_show(args):
394
- emit(request(args, "GET", "/api/orgs/me"))
403
+ # What a person asks "which organisation am I in" for -- not the billing
404
+ # identifiers, purchase tokens and join codes the same row also carries.
405
+ org = request(args, "GET", "/api/orgs/me")
406
+ out = {k: org.get(k) for k in ORG_FIELDS}
407
+ out["entra_sign_in"] = bool(org.get("entra_sign_in"))
408
+ out["members"] = [{k: m.get(k) for k in ("name", "email", "roles")} for m in org.get("members") or []]
409
+ emit(out)
410
+
411
+
412
+ def org_entra_show(args):
413
+ emit(request(args, "GET", "/api/orgs/me/entra"))
414
+
415
+
416
+ def org_entra_set(args):
417
+ """Sign-in with the organisation's own Microsoft Entra ID tenant.
418
+
419
+ The client secret is read from ARCH_ENTRA_CLIENT_SECRET or asked for, never
420
+ taken as an argument (it would land in shell history). Leaving it empty on
421
+ a change keeps the secret already stored."""
422
+ secret = os.environ.get("ARCH_ENTRA_CLIENT_SECRET")
423
+ if secret is None and sys.stdin.isatty():
424
+ secret = getpass.getpass("Client secret (Value; empty keeps the stored one): ")
425
+ body = {"tenant_id": args.tenant_id, "client_id": args.client_id}
426
+ if secret:
427
+ body["client_secret"] = secret
428
+ if args.domain:
429
+ body["domain"] = args.domain
430
+ emit(request(args, "PUT", "/api/orgs/me/entra", body))
431
+
432
+
433
+ def org_entra_disable(args):
434
+ emit(request(args, "DELETE", "/api/orgs/me/entra"))
395
435
 
396
436
 
397
437
  def org_logo(args):
@@ -574,6 +614,14 @@ def _comms_parsers(areas) -> None:
574
614
  og.add_parser("show").set_defaults(func=org_show)
575
615
  lo = og.add_parser("logo", help="Set the logo shown in e-mail and the app")
576
616
  lo.add_argument("file"); lo.set_defaults(func=org_logo)
617
+ en = og.add_parser("entra", help="Sign-in with your Microsoft Entra ID (by organisation name)") .add_subparsers(dest="entra_action", required=True)
618
+ en.add_parser("show", help="The setup, and the Redirect URI to register in Entra").set_defaults(func=org_entra_show)
619
+ es = en.add_parser("set", help="Turn it on or change it; secret from ARCH_ENTRA_CLIENT_SECRET or asked for")
620
+ es.add_argument("--tenant-id", required=True, help="Directory (tenant) ID")
621
+ es.add_argument("--client-id", required=True, help="Application (client) ID")
622
+ es.add_argument("--domain", help="Optional proven domain whose addresses go to Entra by themselves")
623
+ es.set_defaults(func=org_entra_set)
624
+ en.add_parser("disable").set_defaults(func=org_entra_disable)
577
625
 
578
626
 
579
627
  def build_parser():
@@ -1,10 +1,10 @@
1
1
  """Projects, tasks and helpdesk tickets from the command line.
2
2
 
3
3
  `arch project import` takes a whole plan in one JSON file -- projects, their
4
- tasks, and a status log kept as a ticket -- so a list kept somewhere else
5
- (a OneNote page, a spreadsheet) comes over in one command instead of
6
- hundreds of clicks. It is re-runnable: a project that already exists by name
7
- is reported and left alone, so a second run creates nothing twice.
4
+ tasks, and a dated status log kept on the project -- so a list kept somewhere
5
+ else (a OneNote page, a spreadsheet) comes over in one command instead of
6
+ hundreds of clicks. It is quiet (no notification per task, nothing filed in
7
+ the helpdesk) and resumable: run it again and it adds only what is missing.
8
8
 
9
9
  {"projects": [{
10
10
  "name": "Webshop", "priority": "high", "status": "active",
@@ -12,8 +12,7 @@ is reported and left alone, so a second run creates nothing twice.
12
12
  "tasks": [{"title": "Release Stripe production account",
13
13
  "assignees": ["someone@example.com"], "due_date": "2026-09-14",
14
14
  "status": "done", "priority": "medium", "description": "..."}],
15
- "log": {"title": "Webshop - status log",
16
- "entries": ["2026-09-05: URL redirected by nginx ...", "..."]}
15
+ "log": {"entries": ["2026-09-05: URL redirected by nginx ...", "..."]}
17
16
  }],
18
17
  "documents": [{"title": "CCB 2026-10-05", "folder": "Change Control Board",
19
18
  "body": "# Markdown ...", "project": "Webshop"}]}
@@ -86,49 +85,71 @@ def import_documents(request, args, docs: list[dict], dry_run: bool) -> dict:
86
85
  return {"documents_created": made, "documents_skipped": skipped}
87
86
 
88
87
 
88
+ LOG_HEADING = "## Status log"
89
+
90
+
91
+ def _description(spec: dict) -> str:
92
+ """The project description, with the dated status log under its own
93
+ heading. The log used to become a helpdesk ticket: an internal running
94
+ note filed in the support queue, which notified every helpdesk member
95
+ once per project. It is part of the project, so it lives on it."""
96
+ text = (spec.get("description") or "").rstrip()
97
+ entries = [str(e).strip() for e in ((spec.get("log") or {}).get("entries") or []) if str(e).strip()]
98
+ if entries:
99
+ text += ("\n\n" if text else "") + LOG_HEADING + "\n\n" + "\n".join(f"- {e}" for e in entries)
100
+ return text
101
+
102
+
89
103
  def import_plan(request, args, projects: list[dict], dry_run: bool) -> dict:
90
- """Create what does not exist yet; return what was done."""
104
+ """Create what does not exist yet; return what was done.
105
+
106
+ Quiet by design: tasks are created with notify=false, and nothing is
107
+ filed in the helpdesk. Moving a list in is one event for the people on
108
+ it, not one e-mail per line -- whoever imports tells them once.
109
+
110
+ Re-runnable and resumable: a project that exists by name gets the tasks
111
+ it is missing (by title) and its description brought up to date, so an
112
+ import stopped half-way is finished by running it again.
113
+ """
91
114
  existing = {(p.get("name") or "").strip().casefold(): p
92
115
  for p in request(args, "GET", "/api/projects")}
93
- report = {"projects_created": 0, "projects_skipped": [], "tasks_created": 0,
94
- "tickets_created": 0, "log_entries": 0}
116
+ report = {"projects_created": 0, "projects_resumed": [], "tasks_created": 0,
117
+ "tasks_already_there": 0, "log_entries": 0}
95
118
  for spec in projects:
96
119
  name = spec["name"].strip()
97
- if name.casefold() in existing:
98
- report["projects_skipped"].append(name)
99
- continue
100
- if dry_run:
120
+ description = _description(spec)
121
+ report["log_entries"] += len((spec.get("log") or {}).get("entries") or [])
122
+ project = existing.get(name.casefold())
123
+ have: set[str] = set()
124
+ if project:
125
+ report["projects_resumed"].append(name)
126
+ have = {(t.get("title") or "").strip().casefold()
127
+ for t in request(args, "GET", f"/api/agile/tasks?project_id={project['id']}")}
128
+ if not dry_run and (project.get("description") or "") != description:
129
+ request(args, "PUT", f"/api/projects/{project['id']}", {**project, "description": description})
130
+ elif dry_run:
101
131
  report["projects_created"] += 1
102
- report["tasks_created"] += len(spec.get("tasks") or [])
103
- continue
104
- ticket_note = ""
105
- log = spec.get("log") or {}
106
- entries = [e for e in (log.get("entries") or []) if str(e).strip()]
107
- if entries:
108
- ticket = request(args, "POST", "/api/tickets", {
109
- "title": log.get("title") or f"{name} - status log",
110
- "message": entries[0],
132
+ else:
133
+ project = request(args, "POST", "/api/projects", {
134
+ "name": name,
135
+ "status": spec.get("status") or "active",
111
136
  "priority": spec.get("priority") or "medium",
137
+ "description": description,
112
138
  })
113
- for entry in entries[1:]:
114
- request(args, "POST", f"/api/tickets/{ticket['id']}/reply", {"message": entry})
115
- report["tickets_created"] += 1
116
- report["log_entries"] += len(entries)
117
- ticket_note = f"\n\nStatus log: helpdesk ticket #{ticket['id']}."
118
- project = request(args, "POST", "/api/projects", {
119
- "name": name,
120
- "status": spec.get("status") or "active",
121
- "priority": spec.get("priority") or "medium",
122
- "description": (spec.get("description") or "") + ticket_note,
123
- })
124
- report["projects_created"] += 1
139
+ report["projects_created"] += 1
125
140
  for t in spec.get("tasks") or []:
141
+ if t["title"].strip().casefold() in have:
142
+ report["tasks_already_there"] += 1
143
+ continue
144
+ report["tasks_created"] += 1
145
+ if dry_run:
146
+ continue
126
147
  body = {"title": t["title"], "project_id": project["id"],
127
148
  "status": t.get("status") or "todo",
128
- "priority": t.get("priority") or spec.get("priority") or "medium"}
149
+ "priority": t.get("priority") or spec.get("priority") or "medium",
150
+ "notify": False}
129
151
  for key in ("description", "due_date", "assignees"):
130
152
  if t.get(key):
131
153
  body[key] = t[key]
132
154
  request(args, "POST", "/api/agile/tasks", body)
133
- report["tasks_created"] += 1
134
155
  return report
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: arch-insight-cli
3
- Version: 0.3.0
3
+ Version: 0.4.1
4
4
  Summary: Command-line client for ARCH-Insight tasks, factsheets, secrets, and developer platform.
5
5
  Requires-Python: >=3.10
6
6
  Description-Content-Type: text/markdown
@@ -91,6 +91,23 @@ arch project import plan.json
91
91
 
92
92
  See `arch_cli/work.py` for the file format.
93
93
 
94
+ ## Organisation
95
+
96
+ ```sh
97
+ arch org show # name, members, whether Entra sign-in is on
98
+ arch org entra show # the Redirect URI to register in Entra
99
+ ARCH_ENTRA_CLIENT_SECRET=... arch org entra set --tenant-id <Directory ID> --client-id <Application ID>
100
+ ```
101
+
102
+ With Entra sign-in on, members choose "Sign in with your organization" on the
103
+ login screen and type the organisation's name. `--domain` (a domain proven
104
+ under Organization -> Access) also sends that domain's addresses to Entra by
105
+ themselves. The secret is read from `ARCH_ENTRA_CLIENT_SECRET` or asked for,
106
+ never taken as an argument.
107
+
108
+ `arch login` prints the organisation it signed in to. A browser sign-in uses
109
+ the account that browser is signed in to; check it before importing.
110
+
94
111
  ## Marketing e-mail
95
112
 
96
113
  Contact lists drop malformed addresses and reserved domains (`example.com`,
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "arch-insight-cli"
3
- version = "0.3.0"
3
+ version = "0.4.1"
4
4
  description = "Command-line client for ARCH-Insight tasks, factsheets, secrets, and developer platform."
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.10"
@@ -14,7 +14,7 @@ def test_reserved_and_malformed_addresses_are_not_usable():
14
14
 
15
15
  def test_an_excluded_domain_takes_its_subdomains_with_it():
16
16
  assert comms.excluded_by("a@arch-insight.com", ["arch-insight.com"])
17
- assert comms.excluded_by("a@ai-charge.arch-insight.com", ["arch-insight.com"])
17
+ assert comms.excluded_by("a@example.arch-insight.com", ["arch-insight.com"])
18
18
  assert not comms.excluded_by("a@notarch-insight.com", ["arch-insight.com"])
19
19
 
20
20
 
@@ -0,0 +1,129 @@
1
+ """`arch project import`: a whole plan in one command, re-runnable."""
2
+ import json
3
+ from types import SimpleNamespace
4
+
5
+ import pytest
6
+
7
+ from arch_cli import main, work
8
+
9
+ PLAN = {"projects": [{"name": "Webshop", "priority": "high",
10
+ "tasks": [{"title": "Release Stripe", "assignees": ["st@x.com"], "due_date": "2026-09-14"},
11
+ {"title": "Go live", "status": "done"}],
12
+ "log": {"entries": ["2026-09-05: redirected", "2026-09-14: terms updated"]}},
13
+ {"name": "Existing"}],
14
+ "documents": [{"title": "CCB 2026-10-05", "folder": "CCB", "body": "# x", "project": "Webshop"},
15
+ {"title": "Old", "folder": "CCB", "body": "y"}]}
16
+
17
+
18
+ def fake_server():
19
+ calls = []
20
+ state = {"projects": [{"id": 1, "name": "Existing", "description": "old: helpdesk ticket #5"}],
21
+ "tasks": {1: [{"title": "Already here"}]},
22
+ "docs": [{"title": "Old", "folder": "CCB"}]}
23
+
24
+ def request(args, method, path, body=None, **kw):
25
+ calls.append((method, path, body))
26
+ if (method, path) == ("GET", "/api/projects"):
27
+ return state["projects"]
28
+ if (method, path) == ("GET", "/api/docs/requirements"):
29
+ return state["docs"]
30
+ if method == "GET" and path.startswith("/api/agile/tasks?project_id="):
31
+ return state["tasks"].get(int(path.rsplit("=", 1)[1]), [])
32
+ if (method, path) == ("POST", "/api/projects"):
33
+ row = {"id": 10 + len(state["projects"]), **body}
34
+ state["projects"].append(row)
35
+ return row
36
+ return {}
37
+ return request, calls
38
+
39
+
40
+ def test_a_plan_creates_projects_and_tasks_quietly_with_the_log_on_the_project(tmp_path):
41
+ f = tmp_path / "plan.json"
42
+ f.write_text(json.dumps(PLAN), encoding="utf-8")
43
+ request, calls = fake_server()
44
+ report = work.import_plan(request, SimpleNamespace(), work.load_plan(str(f)), dry_run=False)
45
+ assert report["projects_created"] == 1 and report["tasks_created"] == 2
46
+ tasks = [b for m, p, b in calls if (m, p) == ("POST", "/api/agile/tasks")]
47
+ assert tasks[0]["assignees"] == ["st@x.com"] and tasks[0]["due_date"] == "2026-09-14"
48
+ assert tasks[1]["status"] == "done"
49
+ # Nobody is notified per task, and nothing goes to the helpdesk.
50
+ assert all(b["notify"] is False for b in tasks)
51
+ assert not [p for m, p, b in calls if p.startswith("/api/tickets")]
52
+ project = next(b for m, p, b in calls if (m, p) == ("POST", "/api/projects"))
53
+ assert "## Status log" in project["description"]
54
+ assert "- 2026-09-14: terms updated" in project["description"]
55
+
56
+
57
+ def test_a_stopped_import_is_finished_by_running_it_again(tmp_path):
58
+ plan = {"projects": [{"name": "Existing", "tasks": [{"title": "Already here"}, {"title": "New one"}],
59
+ "log": {"entries": ["2026-10-01: started"]}}]}
60
+ f = tmp_path / "plan.json"
61
+ f.write_text(json.dumps(plan), encoding="utf-8")
62
+ request, calls = fake_server()
63
+ report = work.import_plan(request, SimpleNamespace(), work.load_plan(str(f)), dry_run=False)
64
+ assert report["projects_resumed"] == ["Existing"]
65
+ assert report["tasks_created"] == 1 and report["tasks_already_there"] == 1
66
+ put = next(b for m, p, b in calls if (m, p) == ("PUT", "/api/projects/1"))
67
+ assert "helpdesk ticket" not in put["description"] and "2026-10-01: started" in put["description"]
68
+
69
+
70
+ def test_a_dry_run_counts_the_same_and_writes_nothing(tmp_path):
71
+ f = tmp_path / "plan.json"
72
+ f.write_text(json.dumps(PLAN), encoding="utf-8")
73
+ request, calls = fake_server()
74
+ report = work.import_plan(request, SimpleNamespace(), work.load_plan(str(f)), dry_run=True)
75
+ assert report["projects_created"] == 1 and report["tasks_created"] == 2 and report["log_entries"] == 2
76
+ assert not [c for c in calls if c[0] != "GET"]
77
+
78
+
79
+ def test_documents_are_notes_and_not_created_twice(tmp_path):
80
+ f = tmp_path / "plan.json"
81
+ f.write_text(json.dumps(PLAN), encoding="utf-8")
82
+ request, calls = fake_server()
83
+ work.import_plan(request, SimpleNamespace(), work.load_plan(str(f)), dry_run=False)
84
+ report = work.import_documents(request, SimpleNamespace(), work.load_documents(str(f)), dry_run=False)
85
+ assert report == {"documents_created": 1, "documents_skipped": 1}
86
+ doc = next(b for m, p, b in calls if (m, p) == ("POST", "/api/docs/requirements"))
87
+ assert doc["template"] == "note" and doc["folder"] == "CCB" and doc["project_id"] == 11
88
+
89
+
90
+ def test_a_bad_plan_is_refused_before_anything_is_sent(tmp_path):
91
+ f = tmp_path / "plan.json"
92
+ f.write_text(json.dumps({"projects": [{"name": "X", "tasks": [{"title": "t", "status": "nope"}]}]}),
93
+ encoding="utf-8")
94
+ with pytest.raises(work.WorkError):
95
+ work.load_plan(str(f))
96
+
97
+
98
+ def test_the_new_commands_parse():
99
+ parser = main.build_parser()
100
+ for argv in (["project", "list"], ["project", "create", "Webshop", "--priority", "high"],
101
+ ["project", "import", "plan.json", "--dry-run"],
102
+ ["task", "update", "5", "--status", "in_review", "--assignee", "a@b.c"],
103
+ ["ticket", "create", "T", "--message", "m"], ["ticket", "reply", "3", "--message", "m"],
104
+ ["ticket", "status", "3", "pending_customer"],
105
+ ["document", "create", "Minutes", "--file", "m.md", "--folder", "CCB"]):
106
+ assert callable(parser.parse_args(argv).func), argv
107
+
108
+
109
+ def test_org_entra_sends_the_secret_only_from_the_environment(monkeypatch):
110
+ sent = []
111
+ monkeypatch.setattr(main, "request", lambda args, method, path, body=None, **kw: sent.append((method, path, body)) or {})
112
+ monkeypatch.setattr(main, "emit", lambda value: None)
113
+ monkeypatch.setenv("ARCH_ENTRA_CLIENT_SECRET", "s3cret")
114
+ args = main.build_parser().parse_args(["org", "entra", "set", "--tenant-id", "t", "--client-id", "c"])
115
+ args.func(args)
116
+ assert sent == [("PUT", "/api/orgs/me/entra", {"tenant_id": "t", "client_id": "c", "client_secret": "s3cret"})]
117
+
118
+
119
+ def test_org_show_leaves_out_billing_identifiers(monkeypatch):
120
+ shown = []
121
+ monkeypatch.setattr(main, "request", lambda *a, **kw: {"id": 7, "name": "X", "stripe_customer_id": "cus_1",
122
+ "play_purchase_token": "tok", "join_code": "J",
123
+ "members": [{"name": "a", "email": "a@x", "roles": ["Admin"], "bio": "b"}]})
124
+ monkeypatch.setattr(main, "emit", shown.append)
125
+ args = main.build_parser().parse_args(["org", "show"])
126
+ args.func(args)
127
+ text = str(shown[0])
128
+ assert "cus_1" not in text and "tok" not in text and "'J'" not in text
129
+ assert shown[0]["members"] == [{"name": "a", "email": "a@x", "roles": ["Admin"]}]
@@ -1,80 +0,0 @@
1
- """`arch project import`: a whole plan in one command, re-runnable."""
2
- import json
3
- from types import SimpleNamespace
4
-
5
- import pytest
6
-
7
- from arch_cli import main, work
8
-
9
- PLAN = {"projects": [{"name": "Webshop", "priority": "high",
10
- "tasks": [{"title": "Release Stripe", "assignees": ["st@x.com"], "due_date": "2026-09-14"},
11
- {"title": "Go live", "status": "done"}],
12
- "log": {"entries": ["2026-09-05: redirected", "2026-09-14: terms updated"]}},
13
- {"name": "Existing"}],
14
- "documents": [{"title": "CCB 2026-10-05", "folder": "CCB", "body": "# x", "project": "Webshop"},
15
- {"title": "Old", "folder": "CCB", "body": "y"}]}
16
-
17
-
18
- def fake_server():
19
- calls = []
20
- state = {"projects": [{"id": 1, "name": "Existing"}], "docs": [{"title": "Old", "folder": "CCB"}]}
21
-
22
- def request(args, method, path, body=None, **kw):
23
- calls.append((method, path, body))
24
- if (method, path) == ("GET", "/api/projects"):
25
- return state["projects"]
26
- if (method, path) == ("GET", "/api/docs/requirements"):
27
- return state["docs"]
28
- if (method, path) == ("POST", "/api/projects"):
29
- row = {"id": 10 + len(state["projects"]), **body}
30
- state["projects"].append(row)
31
- return row
32
- if (method, path) == ("POST", "/api/tickets"):
33
- return {"id": 77}
34
- return {}
35
- return request, calls
36
-
37
-
38
- def test_a_plan_creates_projects_tasks_and_the_status_log(tmp_path):
39
- f = tmp_path / "plan.json"
40
- f.write_text(json.dumps(PLAN), encoding="utf-8")
41
- request, calls = fake_server()
42
- report = work.import_plan(request, SimpleNamespace(), work.load_plan(str(f)), dry_run=False)
43
- assert report == {"projects_created": 1, "projects_skipped": ["Existing"], "tasks_created": 2,
44
- "tickets_created": 1, "log_entries": 2}
45
- tasks = [b for m, p, b in calls if (m, p) == ("POST", "/api/agile/tasks")]
46
- assert tasks[0]["assignees"] == ["st@x.com"] and tasks[0]["due_date"] == "2026-09-14"
47
- assert tasks[1]["status"] == "done"
48
- project = next(b for m, p, b in calls if (m, p) == ("POST", "/api/projects"))
49
- assert "ticket #77" in project["description"]
50
- assert [b["message"] for m, p, b in calls if p == "/api/tickets/77/reply"] == ["2026-09-14: terms updated"]
51
-
52
-
53
- def test_documents_are_notes_and_not_created_twice(tmp_path):
54
- f = tmp_path / "plan.json"
55
- f.write_text(json.dumps(PLAN), encoding="utf-8")
56
- request, calls = fake_server()
57
- work.import_plan(request, SimpleNamespace(), work.load_plan(str(f)), dry_run=False)
58
- report = work.import_documents(request, SimpleNamespace(), work.load_documents(str(f)), dry_run=False)
59
- assert report == {"documents_created": 1, "documents_skipped": 1}
60
- doc = next(b for m, p, b in calls if (m, p) == ("POST", "/api/docs/requirements"))
61
- assert doc["template"] == "note" and doc["folder"] == "CCB" and doc["project_id"] == 11
62
-
63
-
64
- def test_a_bad_plan_is_refused_before_anything_is_sent(tmp_path):
65
- f = tmp_path / "plan.json"
66
- f.write_text(json.dumps({"projects": [{"name": "X", "tasks": [{"title": "t", "status": "nope"}]}]}),
67
- encoding="utf-8")
68
- with pytest.raises(work.WorkError):
69
- work.load_plan(str(f))
70
-
71
-
72
- def test_the_new_commands_parse():
73
- parser = main.build_parser()
74
- for argv in (["project", "list"], ["project", "create", "Webshop", "--priority", "high"],
75
- ["project", "import", "plan.json", "--dry-run"],
76
- ["task", "update", "5", "--status", "in_review", "--assignee", "a@b.c"],
77
- ["ticket", "create", "T", "--message", "m"], ["ticket", "reply", "3", "--message", "m"],
78
- ["ticket", "status", "3", "pending_customer"],
79
- ["document", "create", "Minutes", "--file", "m.md", "--folder", "CCB"]):
80
- assert callable(parser.parse_args(argv).func), argv