Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions bin/fm-home-seed.sh
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,10 @@ seed_rollback() {
fi
fi

if [ "${SEED_BACKLOG_CREATED:-0}" = 1 ] && [ -n "${SEED_HOME:-}" ] && [ -f "$SEED_HOME/data/backlog.md" ]; then
rm -f -- "$SEED_HOME/data/backlog.md"
fi

if [ -n "${SEED_BACKUP_DIR:-}" ]; then
restore_seed_file "$SEED_PARENT_REG_EXISTED" "$SEED_BACKUP_DIR/parent-secondmates.md" "$REG"
rm -rf -- "$SEED_BACKUP_DIR" 2>/dev/null || true
Expand Down Expand Up @@ -860,6 +864,7 @@ seed_home() {
SEED_HOME_CREATED=0
SEED_HOME_ACQUIRED=0
SEED_HOME_BACKED_UP=0
SEED_BACKLOG_CREATED=0
SEED_BACKUP_DIR=$(mktemp -d "${TMPDIR:-/tmp}/fm-home-seed.XXXXXX")
SEED_CREATED_PROJECTS_FILE="$SEED_BACKUP_DIR/created-projects"
: > "$SEED_CREATED_PROJECTS_FILE"
Expand Down Expand Up @@ -901,6 +906,15 @@ seed_home() {
fi
fi
mkdir -p "$DATA" "$home/data" "$home/state" "$home/config" "$home/projects"
if [ -L "$home/data/backlog.md" ] || { [ -e "$home/data/backlog.md" ] && [ ! -f "$home/data/backlog.md" ]; }; then
echo "error: secondmate backlog must be a regular file inside the home: $home/data/backlog.md" >&2
return 1
fi
if [ ! -e "$home/data/backlog.md" ]; then
printf '## In flight\n\n## Queued\n\n## Done\n' > "$home/data/backlog.md.tmp.$$"
mv -f -- "$home/data/backlog.md.tmp.$$" "$home/data/backlog.md"
SEED_BACKLOG_CREATED=1
fi
if [ -f "$home/data/projects.md" ]; then
SEED_SUB_REG_EXISTED=1
cp "$home/data/projects.md" "$SEED_BACKUP_DIR/sub-projects.md"
Expand Down Expand Up @@ -980,6 +994,9 @@ seed_home() {
mv -f -- "$home/$SUB_HOME_MARKER.tmp.$$" "$home/$SUB_HOME_MARKER"
write_registry "$id" "$home" "$projects_csv" "$SEED_PARENT_BRIEF"
validate_registry
FM_HOME="$home" FM_ROOT_OVERRIDE="$home" FM_STATE_OVERRIDE="$home/state" \
FM_DATA_OVERRIDE="$home/data" FM_CONFIG_OVERRIDE="$home/config" \
FM_PROJECTS_OVERRIDE="$home/projects" "$FM_ROOT/bin/fm-home-summary-refresh.sh" --best-effort || true
SEED_COMMITTED=1
seed_registry_lock_release
trap - EXIT
Expand Down
4 changes: 4 additions & 0 deletions tests/fm-secondmate-safety.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,10 @@ test_home_seed_no_projects_end_to_end() {
assert_grep 'projects: ;' "$home/data/secondmates.md" "project-less registry did not render an empty projects field"
[ "$(cat "$sub/.fm-secondmate-home")" = fdev ] || fail "project-less seed did not mark the subhome"
assert_present "$sub/data/charter.md" "project-less seed did not copy the charter"
assert_present "$sub/data/backlog.md" "seed did not create the secondmate backlog before publication"
assert_present "$sub/state/home-summary.json" "seed did not publish the home summary after creating the backlog"
jq -e '.valid == true and .invalidity.kind == null' "$sub/state/home-summary.json" >/dev/null \
|| fail "seed published an invalid summary after creating the backlog"
[ -z "$(ls -A "$sub/projects" 2>/dev/null)" ] || fail "project-less seed cloned a project"
FM_HOME="$home" "$ROOT/bin/fm-home-seed.sh" validate >/dev/null || fail "registry validation failed after project-less seed"

Expand Down