I need to understand how to build an integration-style test suite that exercises the full desloppify lifecycle: scan → subjective review → score → triage. I need to understand:
How scan produces state (what does a realistic state-typescript.json look like after scan?)
How subjective reviews work — what does subjective_assessments look like in state after real reviews? What does dimension_scores look like with real vs placeholder data?
How the plan/queue_order gets populated — what does plan.json look like?
How reconcile injects workflow items (communicate-score, create-plan, triage stages)
What existing test helpers/fixtures exist for creating realistic state
Search in:
desloppify/tests/ for existing test helpers, fixtures, state factories
desloppify/app/commands/scan/plan_reconcile.py for reconcile logic
desloppify/engine/_work_queue/ for how build_work_queue works
desloppify/engine/_plan/ for plan schema/structure
Any .desloppify/ example state files
desloppify/tests/commands/scan/test_plan_reconcile.py for reconcile test patterns
Focus on: what minimum state shape is needed, how queue_order works, what reconcile expects, and how existing tests fake state.
Assistant
I'll systematically explore the codebase to understand the full lifecycle. Let me search multiple areas in parallel.
Assistant
Now let me read the plan schema, work queue, and some key test helpers in parallel.
Assistant
Now let me read the plan schema, the work queue core, and look for state examples.
Assistant
Now let me look at the state module, the state.py (scoring), and look for any realistic state JSON examples and the review commands cases.
Assistant
Now let me look at the real state and plan JSON files and the state module.
Assistant
Let me now read the actual state-python.json and plan.json from the real .desloppify directory to understand realistic shapes, plus the state module.
Assistant
Now let me look at the state.py module for empty_state, score_snapshot, and the stale_dimensions module.
Assistant
Now let me look at the scan preflight test and stale_policy module, and look at the empty_state function.
Assistant
User
I need to find:
The full list of subjective dimension keys/names used in the system. Search for where dimensions are defined — likely in a registry, config, or constants file. Check desloppify/base/registry.py, any dimension-related files in desloppify/engine/, and desloppify/languages/typescript/ for TS-specific dimensions.
How review_issue_snapshot_hash works in desloppify/engine/_plan/stale_dimensions.py — the exact function and what triggers triage injection.
How _sync_triage_and_log decides whether to inject triage stages — what conditions must be met.
What _sync_communicate_score_and_log and _sync_create_plan_and_log check before injecting their items.
How build_work_queue constructs workflow items — check desloppify/engine/_work_queue/synthetic_workflow.py for build_score_checkpoint_item and build_create_plan_item.
What the _has_initial_reviews function checks in core.py.
Be thorough — read the actual function bodies, not just signatures.
Assistant
I'll search for all these items in parallel.
Assistant
Now let me read the remaining files in parallel.
Assistant
Now let me look for the subjective dimension keys specifically, and where they are defined:
Assistant
Now let me also check if there are language-specific dimension additions (e.g., TypeScript-specific):
Assistant
Now let me check for any language-specific dimension additions — particularly TypeScript or Python:
Assistant
Now I have a thorough understanding of everything. Let me compile the comprehensive report.
Here is a thorough breakdown of every layer you asked about.
The placeholder flag in the detectors.subjective_assessment sub-dict is what the queue lifecycle filter keyed as "initial reviews" gating. The stale flag in dimension_scores (the top-level dict entry, not in detectors) matters for the stale-dimension sync.
3. How plan.json is structured
empty_plan() (desloppify/engine/_plan/schema.py) gives you the full v7 shape:
python
{
"version": 7,
"created": "<now>",
"updated": "<now>",
"queue_order": [], # THE ordering list — all item IDs in priority order
"deferred": [], # legacy/empty compat field
"skipped": {}, # {issue_id: SkipEntry}
"active_cluster": None, # name of focused cluster or None
"overrides": {}, # {issue_id: ItemOverride}
"clusters": {}, # {cluster_name: Cluster}
"superseded": {}, # {old_issue_id: SupersededEntry}
"promoted_ids": [], # IDs explicitly positioned by user
"plan_start_scores": {}, # frozen at start of cycle: {"strict": 85.0, ...}
"execution_log": [], # [{timestamp, action, issue_ids, actor, ...}]
"epic_triage_meta": {}, # triage stage progress tracker
"commit_log": [],
"uncommitted_issues": [],
"commit_tracking_branch": None,
}
What queue_order actually contains
queue_order is a list of string IDs. These can be:
Objective issue IDs: "unused::src/a.ts::foo", "structural::src/b.py", etc.
reconcile_plan_post_scan() in /desloppify/app/commands/scan/plan_reconcile.py runs after every scan and orchestrates these steps in order:
_apply_plan_reconciliation — Supersedes (moves to superseded) any queue_order/skipped/overrides/cluster-member IDs that no longer exist in state or are no longer status="open". Returns surfaced skips. Only runs when plan has user content (non-empty queue_order, overrides, clusters, or skipped).
_sync_unscored_and_log — Calls sync_unscored_dimensions: prepends subjective::<slug> IDs to the front of queue_order for any dimension that is still a placeholder (never scored). This is onboarding priority.
_sync_stale_and_log — Calls sync_stale_dimensions: prunes already-refreshed subjective IDs from queue_order, and appends stale (needs re-review) subjective IDs to the back when no objective backlog exists.
_sync_triage_and_log — Injects triage::observe, triage::reflect, triage::organize, triage::commit (the four stages) when new review/concerns issues appeared since the last triage hash.
_sync_plan_start_scores_and_log — Seeds plan_start_scores on first scan of a new cycle (when plan_start_scores == {}), or clears it when the queue is drained.
Only saves once — dirty flag accumulates, single save_plan() call at end.
5. Existing test helpers and fixtures
In tests/review/work_queue_cases.py
These are the best minimal state helpers that test queue behavior:
state["subjective_assessments"] — dict keyed by slug (e.g., "naming_quality"). Inner shape: {"score", "placeholder"?} for placeholder, or {"score", "source", "assessed_at", "needs_review_refresh"?, "stale_since"?} for real data.
plan["queue_order"] — list of string IDs (all types mixed together).
plan["epic_triage_meta"]["issue_snapshot_hash"] — SHA-256-based hash of open review issue IDs. Absent or stale hash triggers triage injection.
How the snapshot hash is computed
python
# desloppify/engine/_plan/stale_dimensions.py, line ~330ish
def review_issue_snapshot_hash(state):
ids = sorted(
fid for fid, f in state.get("issues", {}).items()
if f.get("status") == "open"
and f.get("detector") in ("review", "concerns")
)
return hashlib.sha256(json.dumps(ids).encode()).hexdigest()[:16] if ids else ""
8. How build_work_queue uses the plan
The pipeline in build_work_queue() (desloppify/engine/_work_queue/core.py):
The key pattern throughout all existing tests is: mock at I/O boundaries (load_plan/save_plan/load_state), use empty_plan() and hand-crafted state dicts, and call the real engine functions directly. The _make_state + _make_issue pattern in test_plan_reconcile.py and the _issue + _state helpers in work_queue_cases.py are the canonical models for the test suite.
I now have a complete picture of everything asked. Here is the full report:
1. Subjective Dimension Keys
The canonical source is /Users/user_c042661f/Documents/desloppify/desloppify/languages/_framework/review_data/dimensions.json — the default_dimensions list — combined with the DISPLAY_NAMES dict in /Users/user_c042661f/Documents/desloppify/desloppify/base/subjective_dimensions.py.
All legacy keys are preserved unconditionally even when a payload drops them (_build_subjective_dimension_metadata at line 372 of base/subjective_dimensions.py). Legacy keys are also marked enabled_by_default=True by default.
TypeScript-specific: the dimensions.override.json and holistic_dimensions.override.json files for TypeScript only override the prompts for abstraction_fitness — they do not add new dimension keys.
_LEGACY_RESET_ON_SCAN_DIMENSIONS (reset on scan — relevant for staleness):
2. review_issue_snapshot_hash — What It Does and What Triggers Triage Injection
Source: /Users/user_c042661f/Documents/desloppify/desloppify/engine/_plan/stale_policy.py lines 103–113, delegated from stale_dimensions.py line 321–326.
python
def review_issue_snapshot_hash(state: StateModel) -> str:
"""Hash open review/concerns issue IDs to detect triage-relevant changes."""
issues = state.get("issues", {})
review_ids = sorted(
issue_id
for issue_id, issue in issues.items()
if issue.get("status") == "open" and issue.get("detector") in _REVIEW_DETECTORS
)
if not review_ids:
return ""
return hashlib.sha256("|".join(review_ids).encode()).hexdigest()[:16]
_REVIEW_DETECTORS = ("review", "concerns").
It collects all open issue IDs whose detector is "review" or "concerns", sorts them, joins with "|", SHA-256 hashes the result, and returns the first 16 hex characters. Returns "" when there are no such issues.
What triggers triage injection (in sync_triage_needed, lines 386–398 of stale_dimensions.py):
python
if current_hash and current_hash != last_hash:
new_since_triage = _new_review_ids_since_triage(state, meta)
if new_since_triage:
result.injected = _inject_pending_triage_stages(order, plan, confirmed)
else:
# Only resolved issues changed the hash — update silently
meta["issue_snapshot_hash"] = current_hash
plan["epic_triage_meta"] = meta
Triage injection happens only when: (a) there is a current hash (i.e. open review issues exist), (b) the hash differs from the stored meta["issue_snapshot_hash"], AND (c) there are genuinely new issue IDs beyond what was previously triaged (_new_review_ids_since_triage returns non-empty). If the hash changed only because issues were resolved (a subset), the hash is updated silently with no injection.
3. _sync_triage_and_log — Injection Conditions
The actual injection logic lives entirely in sync_triage_needed (the function _sync_triage_and_log wraps it with logging in app/). The conditions governing stage injection are:
No triage stage IDs (triage::observe, triage::reflect, triage::organize, triage::commit) are already in queue_order.
current_hash is non-empty (there are open review/concerns issues).
current_hash != last_hash (the hash has changed since the last recorded snapshot).
_new_review_ids_since_triage(state, meta) returns a non-empty set — there are open review/concerns IDs not in meta["triaged_ids"].
When triage stages are already in the queue, there is an auto-prune path instead: if last_hash exists (prior triage happened), no stages are confirmed yet (not confirmed), and _new_review_ids_since_triage is empty, the stale stages are pruned and the hash updated.
_inject_pending_triage_stages injects only stage names not already in meta.get("triage_stages", {}) (confirmed stage tracking), inserting them after promoted items.
4. _sync_communicate_score_and_log and _sync_create_plan_and_log Injection Conditions
sync_communicate_score_needed (lines 601–645 of stale_dimensions.py)
Guards — does NOT inject if:
WORKFLOW_COMMUNICATE_SCORE_ID is already in queue_order, OR
WORKFLOW_SCORE_CHECKPOINT_ID is already in queue_order (legacy fallback, treated as already present)
Injects if EITHER:
scores_just_imported=True (caller-provided flag indicating an attestation import just occurred), OR
No unscored subjective dimensions remain: not policy.unscored_ids (when policy provided) or not current_unscored_ids(state) (fallback).
Positioning: inserted after the last subjective::* item, before any triage::/workflow:: items.
sync_create_plan_needed (lines 465–516 of stale_dimensions.py)
Guards — does NOT inject if ANY of:
WORKFLOW_CREATE_PLAN_ID already in queue_order
Any TRIAGE_IDS stages are present in queue_order (triage must complete first)
Unscored dimensions remain: policy.unscored_ids or current_unscored_ids(state) non-empty
Then requires:
At least one objective issue exists: policy.has_objective_backlog or any open issue whose detector not in NON_OBJECTIVE_DETECTORS (suppressed-check omitted here unlike SubjectiveVisibility)
Positioning: inserted after the last subjective::, triage::, or workflow:: item — i.e., after score-checkpoint if it was injected.
5. build_work_queue — How Workflow Items Are Constructed
Source: /Users/user_c042661f/Documents/desloppify/desloppify/engine/_work_queue/core.py lines 90–145, with workflow item building at lines 204–221.
The pipeline in build_work_queue:
Gather: build_issue_items() for objective issues, _gather_subjective_items() for subjective dimensions, _gather_workflow_items() for triage/checkpoint/create-plan items.
Score & filter: enrich_with_impact() then drop items below _MIN_STANDALONE_IMPACT = 0.05 (but kind != "issue" items pass unconditionally, as do review/subjective issues).
Plan presort: separate skipped items, stamp plan sort keys.
Lifecycle filter: _apply_lifecycle_filter().
Sort: item_sort_key().
Finalize: truncate to count, optionally add explain metadata.
_gather_workflow_items (lines 204–221):
python
def _gather_workflow_items(state, plan, status):
if not plan or status not in {"open", "all"}:
return []
items = list(build_triage_stage_items(plan, state))
for builder in (
build_score_checkpoint_item,
build_import_scores_item,
build_communicate_score_item,
):
item = builder(plan, state)
if item is not None:
items.append(item)
plan_item = build_create_plan_item(plan)
if plan_item is not None:
items.append(plan_item)
return items
Requires a non-None plan and status in {"open", "all"}.
Checks: WORKFLOW_SCORE_CHECKPOINT_ID in plan.get("queue_order", []). If not, returns None.
When present, reads state_mod.score_snapshot(state) for the current strict score, reads plan["plan_start_scores"]["strict"] for the baseline, computes delta. Returns a WorkQueueItem with:
summary: "Create prioritized plan from review results"
detail: {}
primary_command: desloppify plan resolve "workflow::create-plan" --note "Plan reviewed and queue organized" --confirm
Both items have blocked_by: [] and is_blocked: False. Both are purely presence-gated on queue_order — they do not re-evaluate eligibility conditions at build time; that was done at sync time when the IDs were inserted.
def _has_initial_reviews(items: list[WorkQueueItem]) -> bool:
"""True if any unassessed subjective dimensions need initial review."""
return any(
i.get("kind") == "subjective_dimension"
and i.get("initial_review")
for i in items
)
It checks whether any item in the already-built item list has kind == "subjective_dimension" AND initial_review truthy. The initial_review flag is set on subjective items representing placeholder (never-scored) dimensions — dimensions that have never had any assessment run. This flag comes from build_subjective_items in the synthetic module, which sets initial_review=True for unscored/placeholder dimensions.
This function gates the lifecycle filter (lines 310–318):
python
if _has_initial_reviews(items):
# Phase 1: only initial reviews visible
return [
i for i in items
if i.get("kind") == "subjective_dimension" and i.get("initial_review")
]
When any initial reviews are present, ALL other items (objective issues, triage stages, workflow checkpoints) are hidden. Only the initial-review subjective dimensions are shown.