Skip to content

Commit 737f758

Browse files
committed
fix(scripts): persist .specify/feature.json during feature creation
1 parent 55ff148 commit 737f758

5 files changed

Lines changed: 44 additions & 2 deletions

File tree

scripts/bash/common.sh

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

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
@@ -363,6 +364,7 @@ if [ "$DRY_RUN" != true ]; then
363364
fi
364365

365366
mkdir -p "$FEATURE_DIR"
367+
mkdir -p "$(dirname "$FEATURE_METADATA_FILE")"
366368

367369
if [ ! -f "$SPEC_FILE" ]; then
368370
TEMPLATE=$(resolve_template "spec-template" "$REPO_ROOT") || true
@@ -374,6 +376,14 @@ if [ "$DRY_RUN" != true ]; then
374376
fi
375377
fi
376378

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

scripts/powershell/common.ps1

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

266266
return $null
267267
}
268-

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) {
@@ -342,6 +343,7 @@ if (-not $DryRun) {
342343
}
343344

344345
New-Item -ItemType Directory -Path $featureDir -Force | Out-Null
346+
New-Item -ItemType Directory -Path (Split-Path $featureMetadataFile -Parent) -Force | Out-Null
345347

346348
if (-not (Test-Path -PathType Leaf $specFile)) {
347349
$template = Resolve-Template -TemplateName 'spec-template' -RepoRoot $repoRoot
@@ -352,6 +354,10 @@ if (-not $DryRun) {
352354
}
353355
}
354356

357+
[PSCustomObject]@{
358+
feature_directory = "specs/$branchName"
359+
} | ConvertTo-Json -Compress | Set-Content -Path $featureMetadataFile -Encoding utf8
360+
355361
# Set the SPECIFY_FEATURE environment variable for the current session
356362
$env:SPECIFY_FEATURE = $branchName
357363
}

tests/test_timestamp_branches.py

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

108+
def test_writes_feature_metadata_file(self, git_repo: Path):
109+
"""The create script persists .specify/feature.json for downstream commands."""
110+
import json
111+
112+
result = run_script(git_repo, "--json", "--short-name", "meta-test", "Metadata test")
113+
assert result.returncode == 0, result.stderr
114+
data = json.loads(result.stdout)
115+
116+
metadata_file = git_repo / ".specify" / "feature.json"
117+
assert metadata_file.exists(), "feature metadata file was not created"
118+
metadata = json.loads(metadata_file.read_text(encoding="utf-8"))
119+
assert metadata == {"feature_directory": f"specs/{data['BRANCH_NAME']}"}
120+
108121
def test_long_name_truncation(self, git_repo: Path):
109122
"""Test 5: Long branch name is truncated to <= 244 chars."""
110123
long_name = "a-" * 150 + "end"
@@ -774,3 +787,18 @@ def test_ps_dry_run_json_absent_without_flag(self, ps_git_repo: Path):
774787
assert result.returncode == 0, result.stderr
775788
data = json.loads(result.stdout)
776789
assert "DRY_RUN" not in data, f"DRY_RUN should not be in normal JSON: {data}"
790+
791+
def test_ps_writes_feature_metadata_file(self, ps_git_repo: Path):
792+
"""PowerShell create script persists .specify/feature.json."""
793+
import json
794+
795+
result = run_ps_script(
796+
ps_git_repo, "-Json", "-ShortName", "ps-meta", "PowerShell metadata"
797+
)
798+
assert result.returncode == 0, result.stderr
799+
data = json.loads(result.stdout)
800+
801+
metadata_file = ps_git_repo / ".specify" / "feature.json"
802+
assert metadata_file.exists(), "feature metadata file was not created"
803+
metadata = json.loads(metadata_file.read_text(encoding="utf-8-sig"))
804+
assert metadata == {"feature_directory": f"specs/{data['BRANCH_NAME']}"}

0 commit comments

Comments
 (0)