---
title: "Verification Report: ALKS CLI Keystore — Replace keytar with a Node-24-Compatible Keychain Library"
spec_source: spec-driven/alks-cli-keystore-keytar-replacement/spec.md
spec_hash: sha256:898ed80fae7828d1
plan_source: spec-driven/alks-cli-keystore-keytar-replacement/plan.md
plan_hash: sha256:edc202e5631143d0
task_source: spec-driven/alks-cli-keystore-keytar-replacement/tasks.md
task_hash: sha256:88031a8f974f7c39
progress_source: spec-driven/alks-cli-keystore-keytar-replacement/progress.md
progress_hash: sha256:2e0a3d06cbca8542
status: PASS
date: 2026-07-30
agents_run: [traceability, completeness, quality, testing, regression, security]
total_findings: 14
critical_count: 0
high_count: 0
medium_count: 4
low_count: 4
info_count: 6
---

# Verification Report: ALKS CLI Keystore — Replace keytar with a Node-24-Compatible Keychain Library

> Spec: spec-driven/alks-cli-keystore-keytar-replacement/spec.md | Date: 2026-07-30 | Overall Verdict: **PASS**

## Summary

Verified the replacement of the archived `keytar` with `@napi-rs/keyring` behind the single `getKeytar.ts` adapter across 4 FRs, 13 ACs, 5 NFRs, and 8 tasks (all `done`). The artifact chain is fully intact — every changed file traces to a declared task with a correct `[TASK-N]` commit, and no orphan changes exist. The core change is implemented well: the adapter cleanly preserves the single-boundary design (the library's `AsyncEntry` type never leaks to the three call sites, so `getTokenFromKeystore`/`storeToken`/`removeToken` are unchanged — AC-1.6), missing-entry reads resolve to `undefined` and deletes are no-ops (AC-1.3/1.4), the misleading "No keychain could be found" message is gone in favor of the real cause (AC-2.2), `engines.node` is `>=20` (AC-3.1), and a genuinely non-mocked integration test plus CI gnome-keyring/D-Bus provisioning exercise the real binding on the 20/22/24 matrix (AC-4.1/4.2).

The build, full test suite (43 suites / 390 tests — up from the baseline 39/375 with no regression), and lint are all green, and the real-keychain round-trip runs without prompting. Backward-compat (AC-1.5/NFR-2) was empirically confirmed on macOS during execution: the new adapter read a keytar-format keychain entry and deleted it cleanly.

No CRITICAL or HIGH findings. The 4 MEDIUM findings are quality/robustness improvements rather than defects in delivered behavior: the `isNoEntryError` message-regex could swallow a genuine error on a platform that throws (the reliable `.code` check is in place, but the message fallback is broad); `removeToken` calls the now-async adapter delete without `await` (pre-existing pattern, more meaningful now); AC-1.5 backward-compat is verified only manually, not by a committed test; and AC-2.1's surfaced error still carries an (actionable) "reinstall" hint that a strict reading of the AC excludes. Runtime-only ACs (clean Node-24 published install, CI red/green on push) are legitimately deferred and documented.

---

## Dimension Verdicts

| # | Dimension | Verdict | Findings | Notes |
|---|-----------|---------|----------|-------|
| 1 | Traceability | PASS | 3 (LOW/INFO) | Chain fully intact; all 13 ACs trace to tasks/commits. |
| 2 | AC/NFR Completeness | PASS | 3 (1 MED, LOW/INFO) | AC-2.1 partially literal (reinstall string); rest satisfied. |
| 3 | Code Quality + Conventions | PASS | 2 (1 MED, LOW/INFO) | `isNoEntryError` message heuristic fragile; both CLAUDE.md conventions honored. |
| 4 | Test Quality | PASS | 4 (3 MED, LOW) | Solid unit + non-mocked integration coverage; error/edge-path gaps. |
| 5 | Regression | PASS | 0 | Build, 390 tests, lint all green; no regression vs baseline. |
| 6 | Security | PASS | 4 (LOW/INFO) | Plaintext gate + 0o600 + token redaction preserved; no leak path. |

---

## Findings

### MEDIUM

#### VF-1: `isNoEntryError` message-regex could swallow a genuine error; non-NoEntry propagation untested
- **Dimension**: Code Quality + Conventions (with Test Quality)
- **Evidence**: `src/lib/getKeytar.ts:24-31` (regex `/no (matching )?entry|not found/i`), throw branches at `:62-66` and `:77-82`; `src/lib/getKeytar.test.ts:44-70` only feeds NoEntry-coded errors — the `throw err` (propagation) branches are never exercised.
- **Affected ACs**: AC-1.3, AC-1.4, NFR-4
- **Suggested Fix**: Treat `.code`/`NoEntry` as the primary signal and narrow or drop the message-text fallback (it can false-positive on an unrelated error whose message contains "not found", and false-negative on macOS's own "could not be found" phrasing). Add adapter tests where the fake rejects with a **non**-NoEntry error (code absent, or message like "access denied") and assert `getPassword`/`deletePassword` **reject** rather than resolve.

#### VF-2: `removeToken` does not `await` the now-async adapter delete; no direct test
- **Dimension**: Test Quality (with Code Quality, Security)
- **Evidence**: `src/lib/removeToken.ts:10` calls `keytar.deletePassword(...)` with no `await`/`catch`; the adapter rethrows non-NoEntry errors (`src/lib/getKeytar.ts:77-82`). No `removeToken.test.ts` exists. A real delete failure becomes an unhandled promise rejection *after* `removeToken` resolves, so logout can report success while the credential remains.
- **Affected ACs**: AC-1.4
- **Suggested Fix**: `await` (and optionally try/catch+log) the delete in `removeToken`; add `removeToken.test.ts` asserting the `(alkscli, alkstoken)` call, no-throw on a missing entry, and propagation of a non-NoEntry error.

#### VF-3: AC-1.5 backward-compat (existing-token migration) has no automated test
- **Dimension**: Test Quality (with Traceability)
- **Evidence**: AC-1.5 is Must-Have but evidenced only by the one-off manual macOS check in `progress.md` (Bundle 5 / TASK-8). No committed test guards keytar→napi read compatibility, so a future library change orphaning keytar-format entries would ship green.
- **Affected ACs**: AC-1.5, NFR-2
- **Suggested Fix**: Add a platform-gated (darwin/win32) test that writes a generic-password entry via the OS-native tool (macOS `security add-generic-password`) under a disposable service and asserts the adapter reads it back — mirroring the manual TASK-8 procedure as a committed regression guard.

#### VF-4: AC-2.1 partially literal — surfaced error still contains a "reinstall" string, and that clause isn't locked by a test
- **Dimension**: AC/NFR Completeness
- **Evidence**: `src/lib/getKeytar.ts:46,50` append "…reinstall this tool with 'npm install -g alks'." AC-2.1's Then clause requires the message to *not* print the generic "reinstall" string. The guarding test (`getKeytar.test.ts:164-169`) asserts the real cause is present and the exact-anchored `/^No keychain could be found$/` is absent — it does not pin the "reinstall" clause either way.
- **Affected ACs**: AC-2.1
- **Suggested Fix**: Decide intent — the actionable reinstall hint is good UX, so either relax AC-2.1's wording to allow a remediation hint alongside the real cause (recommended) or drop the reinstall phrasing. Either way, add a test assertion pinning the chosen behavior.

### LOW / INFO

| ID | Severity | Dimension | Title | Evidence |
|----|----------|-----------|-------|----------|
| VF-5 | LOW | Security | Honest-error message interpolates untrusted keychain error into stderr + unredacted `log()` near the secret | `src/lib/storeToken.ts:16-21`; `src/lib/log.ts:84-100` |
| VF-6 | LOW | AC/NFR Completeness | Read path (`getTokenFromKeystore`) stays silent without `-v` — logs cause via `log()` only before plaintext fallback | `src/lib/getTokenFromKeystore.ts:26-32` |
| VF-7 | LOW | Code Quality | `// eslint-disable-next-line` comments are no-ops in a tslint-only project | `src/lib/getKeytar.test.ts:77,93` |
| VF-8 | LOW | Test Quality | AC-1.6 boundary rests on weak `typeof === 'function'` assertions (saved by the ctorArgs check) rather than a structural/grep invariant | `src/lib/getKeytar.test.ts:114-126` |
| VF-9 | INFO | Code Quality | Redundant `?? undefined` at the `getTokenFromKeystore` call site (adapter already normalizes) | `src/lib/getTokenFromKeystore.ts:11` |
| VF-10 | INFO | Code Quality | CI keychain-setup shell lacks `set -euo pipefail`; a keyring-unlock failure is only surfaced via the downstream test | `.github/workflows/build-and-test.yml:65-69` |
| VF-11 | INFO | Security | New native dep `@napi-rs/keyring` — confirm shrinkwrap pins exact version+integrity for it and its per-platform binaries, and that they're mirrored/approved in Artifactory (cai-npm) | `package.json:48`; `.github/workflows/build-and-test.yml:43-48` |
| VF-12 | INFO | Security | Integration test writes a dummy secret ('secret-xyz', not a real token) to the real OS keychain under a disposable service; a hard kill between set and cleanup could leave one stray entry | `src/lib/getKeytar.integration.test.ts:42-53` |
| VF-13 | INFO | Traceability | TASK-8 is verification-only; its `[TASK-8]` tag rides the progress-doc commit `08a3f53` (legitimate — migration check passed, no conditional code needed) | commit `08a3f53`; `progress.md` |
| VF-14 | INFO | Traceability | Deferred ACs (AC-1.1 clean install, AC-1.5 real upgrade, AC-4.2 CI red/green on push) are runtime/post-deploy and legitimately outside local execution | `progress.md`; spec §Post-deploy |

---

## Finding Cross-Reference

| Report ID | Original ID(s) | Dimension |
|-----------|----------------|-----------|
| VF-1 | VF-CQ-1, VF-TE-3 | Code Quality / Test Quality |
| VF-2 | VF-TE-2, VF-CQ-4, VF-SE-2 | Test Quality / Code Quality / Security |
| VF-3 | VF-TE-1, VF-TR-2 | Test Quality / Traceability |
| VF-4 | VF-CO-1 | AC/NFR Completeness |
| VF-5 | VF-SE-1 | Security |
| VF-6 | VF-CO-2, VF-TE-5 | AC/NFR Completeness / Test Quality |
| VF-7 | VF-CQ-2 | Code Quality |
| VF-8 | VF-TE-4 | Test Quality |
| VF-9 | VF-CQ-3 | Code Quality |
| VF-10 | VF-CQ-5 | Code Quality |
| VF-11 | VF-SE-3 | Security |
| VF-12 | VF-SE-4 | Security |
| VF-13 | VF-TR-1 | Traceability |
| VF-14 | VF-TR-3, VF-CO-3 | Traceability / Completeness |

---

## Traceability Matrix

| FR | AC | STEP | TASK | Commit | Code Evidence | Test Evidence |
|----|-----|------|------|--------|---------------|---------------|
| FR-1 | AC-1.1 | STEP-1,5 | TASK-1,5 | ea89952, 52fcc9f | `package.json`; `getKeytar.ts` adapter | `getKeytar.integration.test.ts:38` (round-trip); clean-install deferred |
| FR-1 | AC-1.2 | STEP-2 | TASK-2 | bce37a8 | `getKeytar.ts:56-60` | `getKeytar.test.ts:106` |
| FR-1 | AC-1.3 | STEP-2 | TASK-2 | bce37a8 | `getKeytar.ts:56-66` | `getKeytar.test.ts:129,143` |
| FR-1 | AC-1.4 | STEP-2 | TASK-2 | bce37a8 | `getKeytar.ts:69-82` | `getKeytar.test.ts:134,148` (adapter-level only — see VF-2) |
| FR-1 | AC-1.5 | STEP-8 | TASK-8 | 08a3f53 | `getKeytar.ts` (same keys) | MANUAL (`progress.md`) — no automated test (VF-3) |
| FR-1 | AC-1.6 | STEP-2 | TASK-2 | bce37a8 | `getKeytar.ts` `Keystore` iface; call sites unchanged | `getKeytar.test.ts:114` (thin — VF-8) |
| FR-2 | AC-2.1 | STEP-2 | TASK-2 | bce37a8 | `getKeytar.ts:40-52` | `getKeytar.test.ts:156` (partial — VF-4; read path VF-6) |
| FR-2 | AC-2.2 | STEP-3 | TASK-3 | f06a804 | `storeToken.ts:16-21` | `storeToken.test.ts:31` |
| FR-2 | AC-2.3 | STEP-3 | TASK-3 | f06a804 | `storeToken.ts:27-29`; `getTokenFromKeystore.ts:30` | `storeToken.test.ts:50`; `getTokenFromKeystore.test.ts:27` |
| FR-3 | AC-3.1 | STEP-4,7 | TASK-4,7 | 05dff6e, 1e59912 | `package.json` engines; `changelog.txt` | `node -e` engines check; changelog grep |
| FR-3 | AC-3.2 | STEP-4 | TASK-4 | 05dff6e | `package.json`; napi `engines>=10` | `node -e` lib-floor check |
| FR-4 | AC-4.1 | STEP-5,6 | TASK-5,6 | 52fcc9f, 0a81675 | `getKeytar.integration.test.ts:38`; workflow | integration round-trip (gated); CI push deferred |
| FR-4 | AC-4.2 | STEP-5,6 | TASK-5,6 | 52fcc9f, 0a81675 | `getKeytar.integration.test.ts:29` (load assertion); workflow | load assertion always runs; CI red/green-on-push deferred |

---

## Toolchain Results

| Check | Command | Exit Code | Result | Notes |
|-------|---------|-----------|--------|-------|
| Type Check / Build | `npm run build` (tsc) | 0 | PASS | — |
| Test Suite | `CI=true npx jest --no-watch` | 0 | PASS | 43 suites / 390 tests, 0 failures (+4 suites/+15 tests vs baseline) |
| Lint | `npx tslint 'src/**/*.ts'` | 0 | PASS | Only pre-existing style WARNINGS; 0 errors |
| Real keychain round-trip | (integration test) | 0 | PASS | Ran against real macOS keychain, no prompt |

> Baseline exit code from execution: 0 (39 suites / 375 tests). Current exit code: 0 (43 / 390). Regression: No.

---

## OWASP Top 10 Assessment

| OWASP Category | Status | Finding |
|----------------|--------|---------|
| A01: Broken Access Control | NOT_APPLICABLE | — |
| A02: Cryptographic Failures | PASS | Token kept in OS keychain; plaintext only via explicit confirm + 0o600 |
| A03: Injection | NOT_APPLICABLE | — |
| A04: Insecure Design | PASS | Single adapter boundary; honest-failure fallback gated |
| A05: Security Misconfiguration | PASS | CI empty-keyring password confined to ephemeral dbus-run-session |
| A06: Vulnerable Components | FINDING | VF-11 (new native dep — confirm pin + registry mirror) |
| A07: Auth Failures | NOT_APPLICABLE | — |
| A08: Data Integrity Failures | PASS | — |
| A09: Logging Failures | PASS | Token redaction (`unsafe`/`alt`) preserved; VF-5 LOW note on error interpolation |
| A10: SSRF | NOT_APPLICABLE | — |

---

## Success Criteria

| Metric | Target | Evidence | Status |
|--------|--------|----------|--------|
| Keychain store success on Node 24 (clean install) | Succeeds | macOS round-trip green; clean published-install is post-deploy | CANNOT_VERIFY (post-deploy) |
| Matrix Node versions with working keychain (real path) | 3 of 3 (20/22/24) | Integration test wired into CI matrix; actual CI run on push | CANNOT_VERIFY (deferred to first push) |
| Keystore failures reported with real cause (no `-v`) | 100% | Store path: `storeToken.ts` `console.error` (MET); read path silent (VF-6) | PARTIALLY MET |
| Upgrading users forced to re-authenticate | 0 | Empirical keytar-format read confirmed on macOS (TASK-8) | MET (macOS); CANNOT_VERIFY (other platforms/real upgrade) |

---

## Remediation Log

Applied post-verification in commit `5f5a4d7` (full suite green afterward: 44 suites / 397 passed + 1 skipped; lint clean).

| VF-ID | Action Taken | Result | Re-verified |
|-------|-------------|--------|-------------|
| VF-1 | `isNoEntryError` now keys off the error `.code`; message fallback narrowed to keychain/entry phrasings (dropped bare `/not found/i`). Added tests: non-NoEntry error propagates, message-only NoEntry swallowed, unrelated "file not found" NOT swallowed. | Fixed | Tests pass (getKeytar 12/12) |
| VF-2 | `removeToken` now `await`s the adapter delete so a real failure reaches the logout handler's existing catch. Added `removeToken.test.ts` (key args, no-op on missing, propagation). | Fixed | Tests pass (removeToken 3/3) |
| VF-3 | Added an opt-in (`KEYSTORE_MIGRATION_CHECK=1`, macOS-only) integration test that writes a keytar-format entry via `security` and reads it through the adapter. Gated opt-in because the cross-creator read triggers a macOS keychain ACL prompt that would hang the headless suite/CI — the reason AC-1.5 was a manual check. | Fixed (opt-in) | Skipped in suite; runnable on demand |
| VF-4 | Not remediated — AC-2.1's "no reinstall string" clause is a spec-wording decision (the reinstall hint is intentional, actionable UX). Left for author decision. | Deferred | — |

## Convention Principles Added

| Principle | Target File | Theme | Source Findings |
|-----------|-------------|-------|-------------|
| Classify benign errors by a stable code, not message text; handle or propagate every other error (never silently swallow); always `await` async cleanup so failures surface. | `CLAUDE.md` | Adapter error classification & propagation | VF-1, VF-2 |

## Deferred Verifications

| Task | Criterion | Reason |
|------|-----------|--------|
| TASK-6 | AC-4.2 CI matrix red/green behavior on push | GitHub Actions cannot run locally; also apt/sudo availability on the self-hosted `cai-standard-x86-linux` runner is unverified |
| TASK-8 | AC-1.1 clean Node-24 published-install stores to keychain | Requires the published artifact — post-deploy |
| TASK-8 | AC-1.5 real upgrading user reads pre-existing token (non-macOS) | Requires a real upgrade environment — post-deploy |

---

## Verification Metadata

- **Agents dispatched**: traceability, completeness, quality, testing, regression, security (all `general-purpose`, opus)
- **Execution scope**: 8 of 8 tasks verified (complete)
- **Artifact chain**: complete (spec → plan → tasks → progress → commits)
- **Baseline commit**: 5b7ea93
- **Verification commit range**: 5b7ea93..08a3f53
