summaryrefslogtreecommitdiff
path: root/docs/plans/2026-04-09-crm-property-completion-implementation.md
blob: 88b3d0159baa838ee1e7455c3fa6f4dfedec5a7b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# CRM Property Completion Implementation Plan

> **For Claude:** REQUIRED SUB-SKILL: Use superpowers:executing-plans to implement this plan task-by-task.

**Goal:** Add data-driven CRM property completion and inline value creation to `ss-crm-add` without introducing a second source of truth.

**Architecture:** Extend `lisp/ss-crm.el` with small lookup helpers that build on the existing parsed CRM entry cache, plus a single generic choice reader that handles blank selection, optional freeform values, confirmation, and advisory duplicate warnings. Keep seeded vocabularies in code, wire field-specific readers into `ss-crm-add`, and verify with focused ERT coverage plus batch startup loading.

**Tech Stack:** Emacs Lisp, Org, ERT, batch Emacs verification

---

### Task 1: Add failing CRM helper tests

**Files:**
- Create: `tests/ss-crm-tests.el`
- Modify: `lisp/ss-crm.el`

**Step 1: Write the failing test**

```elisp
(ert-deftest ss-crm-known-property-values-sorts-and-deduplicates ()
  (cl-letf (((symbol-function 'ss-crm-entries)
             (lambda ()
               (list (list :role "Engineer")
                     (list :role " engineer ")
                     (list :role "Architect")
                     (list :role nil)))))
    (should (equal (ss-crm-known-property-values "ROLE")
                   '("Architect" "Engineer" " engineer ")))))
```

**Step 2: Run test to verify it fails**

Run: `emacs --batch -Q -L . -L lisp -l tests/ss-crm-tests.el -f ert-run-tests-batch-and-exit`
Expected: FAIL because the new CRM helper functions do not exist yet.

**Step 3: Write minimal implementation**

```elisp
(defun ss-crm-known-property-values (property)
  ...)
```

**Step 4: Run test to verify it passes**

Run: `emacs --batch -Q -L . -L lisp -l tests/ss-crm-tests.el -f ert-run-tests-batch-and-exit`
Expected: PASS for the helper coverage.

**Step 5: Commit**

```bash
git add tests/ss-crm-tests.el lisp/ss-crm.el
git commit -m "Add CRM property completion helpers"
```

### Task 2: Add completion-reader tests and implement prompt behavior

**Files:**
- Modify: `tests/ss-crm-tests.el`
- Modify: `lisp/ss-crm.el`

**Step 1: Write the failing test**

```elisp
(ert-deftest ss-crm-read-choice-warns-on-new-case-insensitive-duplicate ()
  (let (warning)
    (cl-letf (((symbol-function 'completing-read) (lambda (&rest _) "sydney"))
              ((symbol-function 'yes-or-no-p) (lambda (&rest _) t))
              ((symbol-function 'display-warning)
               (lambda (_type message &rest _) (setq warning message))))
      (should (equal (ss-crm-read-choice "Location: " '("Sydney")
                                         :allow-blank t
                                         :allow-new t)
                     "sydney"))
      (should (string-match-p "Sydney" warning))))
```

**Step 2: Run test to verify it fails**

Run: `emacs --batch -Q -L . -L lisp -l tests/ss-crm-tests.el -f ert-run-tests-batch-and-exit`
Expected: FAIL because `ss-crm-read-choice` does not support the new behavior yet.

**Step 3: Write minimal implementation**

```elisp
(defun ss-crm-read-choice (prompt choices &rest plist)
  ...)
```

**Step 4: Run test to verify it passes**

Run: `emacs --batch -Q -L . -L lisp -l tests/ss-crm-tests.el -f ert-run-tests-batch-and-exit`
Expected: PASS for blank selection, existing completion, and new-value confirmation coverage.

**Step 5: Commit**

```bash
git add tests/ss-crm-tests.el lisp/ss-crm.el
git commit -m "Add CRM completion prompts"
```

### Task 3: Integrate field readers into `ss-crm-add` and verify startup

**Files:**
- Modify: `lisp/ss-crm.el`
- Review: `README.md`

**Step 1: Write the failing test**

```elisp
(ert-deftest ss-crm-read-manager-uses-known-person-names ()
  (cl-letf (((symbol-function 'ss-crm-known-person-names)
             (lambda () '("Alice" "Bob")))
            ((symbol-function 'ss-crm-read-choice)
             (lambda (_prompt choices &rest _plist) choices)))
    (should (equal (ss-crm-read-manager) '("Alice" "Bob")))))
```

**Step 2: Run test to verify it fails**

Run: `emacs --batch -Q -L . -L lisp -l tests/ss-crm-tests.el -f ert-run-tests-batch-and-exit`
Expected: FAIL until the field readers are wired up.

**Step 3: Write minimal implementation**

```elisp
(defun ss-crm-read-manager ()
  (ss-crm-read-choice "Manager: " (ss-crm-known-person-names)
                      :allow-blank t
                      :require-match t))
```

**Step 4: Run test to verify it passes**

Run: `emacs --batch -Q -L . -L lisp -l tests/ss-crm-tests.el -f ert-run-tests-batch-and-exit`
Expected: PASS, then run `emacs --batch -Q --load ./init.el` to confirm startup remains healthy.

**Step 5: Commit**

```bash
git add tests/ss-crm-tests.el lisp/ss-crm.el README.md
git commit -m "Guide CRM add-person property entry"
```