Skip to content

Commit 8009c0d

Browse files
committed
fix(scripts): persist .specify/feature.json during feature creation
1 parent c118c1c commit 8009c0d

File tree

5 files changed

+41
-2
lines changed

5 files changed

+41
-2
lines changed

scripts/bash/common.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,4 +372,3 @@ except Exception:
372372
# Callers running under set -e should use: TEMPLATE=$(resolve_template ...) || true
373373
return 1
374374
}
375-

scripts/bash/create-new-feature.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ fi
324324

325325
FEATURE_DIR="$SPECS_DIR/$BRANCH_NAME"
326326
SPEC_FILE="$FEATURE_DIR/spec.md"
327+
FEATURE_METADATA_FILE="$REPO_ROOT/.specify/feature.json"
327328

328329
if [ "$DRY_RUN" != true ]; then
329330
if [ "$HAS_GIT" = true ]; then
@@ -366,6 +367,7 @@ if [ "$DRY_RUN" != true ]; then
366367
fi
367368

368369
mkdir -p "$FEATURE_DIR"
370+
mkdir -p "$(dirname "$FEATURE_METADATA_FILE")"
369371

370372
if [ ! -f "$SPEC_FILE" ]; then
371373
TEMPLATE=$(resolve_template "spec-template" "$REPO_ROOT") || true
@@ -377,6 +379,14 @@ if [ "$DRY_RUN" != true ]; then
377379
fi
378380
fi
379381

382+
if command -v jq >/dev/null 2>&1; then
383+
jq -cn \
384+
--arg feature_directory "specs/$BRANCH_NAME" \
385+
'{feature_directory:$feature_directory}' >"$FEATURE_METADATA_FILE"
386+
else
387+
printf '{"feature_directory":"%s"}\n' "$(json_escape "specs/$BRANCH_NAME")" >"$FEATURE_METADATA_FILE"
388+
fi
389+
380390
# Inform the user how to persist the feature variable in their own shell
381391
printf '# To persist: export SPECIFY_FEATURE=%q\n' "$BRANCH_NAME" >&2
382392
fi

scripts/powershell/common.ps1

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,4 +353,3 @@ function Resolve-Template {
353353

354354
return $null
355355
}
356-

scripts/powershell/create-new-feature.ps1

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ if ($branchName.Length -gt $maxBranchLength) {
289289

290290
$featureDir = Join-Path $specsDir $branchName
291291
$specFile = Join-Path $featureDir 'spec.md'
292+
$featureMetadataFile = Join-Path $repoRoot '.specify/feature.json'
292293

293294
if (-not $DryRun) {
294295
if ($hasGit) {
@@ -346,6 +347,7 @@ if (-not $DryRun) {
346347
}
347348

348349
New-Item -ItemType Directory -Path $featureDir -Force | Out-Null
350+
New-Item -ItemType Directory -Path (Split-Path $featureMetadataFile -Parent) -Force | Out-Null
349351

350352
if (-not (Test-Path -PathType Leaf $specFile)) {
351353
$template = Resolve-Template -TemplateName 'spec-template' -RepoRoot $repoRoot
@@ -356,6 +358,10 @@ if (-not $DryRun) {
356358
}
357359
}
358360

361+
[PSCustomObject]@{
362+
feature_directory = "specs/$branchName"
363+
} | ConvertTo-Json -Compress | Set-Content -Path $featureMetadataFile -Encoding utf8
364+
359365
# Set the SPECIFY_FEATURE environment variable for the current session
360366
$env:SPECIFY_FEATURE = $branchName
361367
}

tests/test_timestamp_branches.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,19 @@ def test_json_output_keys(self, git_repo: Path):
180180
assert key in data, f"missing {key} in JSON: {data}"
181181
assert re.match(r"^\d{8}-\d{6}$", data["FEATURE_NUM"])
182182

183+
def test_writes_feature_metadata_file(self, git_repo: Path):
184+
"""The create script persists .specify/feature.json for downstream commands."""
185+
import json
186+
187+
result = run_script(git_repo, "--json", "--short-name", "meta-test", "Metadata test")
188+
assert result.returncode == 0, result.stderr
189+
data = json.loads(result.stdout)
190+
191+
metadata_file = git_repo / ".specify" / "feature.json"
192+
assert metadata_file.exists(), "feature metadata file was not created"
193+
metadata = json.loads(metadata_file.read_text(encoding="utf-8"))
194+
assert metadata == {"feature_directory": f"specs/{data['BRANCH_NAME']}"}
195+
183196
def test_long_name_truncation(self, git_repo: Path):
184197
"""Test 5: Long branch name is truncated to <= 244 chars."""
185198
long_name = "a-" * 150 + "end"
@@ -993,7 +1006,19 @@ def test_ps_dry_run_json_absent_without_flag(self, ps_git_repo: Path):
9931006
assert result.returncode == 0, result.stderr
9941007
data = json.loads(result.stdout)
9951008
assert "DRY_RUN" not in data, f"DRY_RUN should not be in normal JSON: {data}"
1009+
1010+
def test_ps_writes_feature_metadata_file(self, ps_git_repo: Path):
1011+
"""PowerShell create script persists .specify/feature.json."""
1012+
result = run_ps_script(
1013+
ps_git_repo, "-Json", "-ShortName", "ps-meta", "PowerShell metadata"
1014+
)
1015+
assert result.returncode == 0, result.stderr
1016+
data = json.loads(result.stdout)
9961017

1018+
metadata_file = ps_git_repo / ".specify" / "feature.json"
1019+
assert metadata_file.exists(), "feature metadata file was not created"
1020+
metadata = json.loads(metadata_file.read_text(encoding="utf-8-sig"))
1021+
assert metadata == {"feature_directory": f"specs/{data['BRANCH_NAME']}"}
9971022

9981023
# ── GIT_BRANCH_NAME Override Tests ──────────────────────────────────────────
9991024

0 commit comments

Comments
 (0)