Skip to content

[BUG] install.sh is not idempotent and creates nested src/tmp/template_project on second run #197

Closed

Description

@c-vigo

Description

Running install.sh a second time in the same target directory creates an unexpected nested folder (src/tmp/template_project/) instead of keeping the workspace clean/idempotent.

Steps to Reproduce

  1. Run:
    ~/Documents/vigOS/devcontainer/install.sh ./ --version dev --skip-pull --force --org vigOS
  2. Confirm working tree is clean:
    git status -> nothing to commit, working tree clean
  3. Run the same install command again in the same directory.
  4. Check status:
    git status -> shows untracked files under src/tmp/template_project/

Expected Behavior

Re-running install.sh on the same directory should be idempotent and should not create additional nested template folders or untracked artifacts.

Actual Behavior

Second execution creates src/tmp/template_project/ as untracked content.

Environment

  • OS: Linux 6.17.0-14-generic
  • Container Runtime: N/A (not involved in reproduction)
  • Image Version/Tag: dev (--version dev)
  • Architecture: x86_64

Additional Context

Reproduction commands/output provided by reporter:

~/Documents/vigOS/devcontainer/install.sh ./ --version dev --skip-pull --force --org vigOS
git status  # clean
~/Documents/vigOS/devcontainer/install.sh ./ --version dev --skip-pull --force --org vigOS
git status  # shows src/tmp/template_project/

Possible Solution

Ensure install.sh handles repeat execution safely by:

  • normalizing target path handling for template copy/sync operations
  • preventing recursive copy into src/ when target is already initialized
  • adding guard clauses for existing destination structure

Changelog Category

Fixed

Acceptance Criteria

  • Re-running install.sh with the same arguments does not create new untracked files/folders
  • src/tmp/template_project/ is not created on second run
  • TDD compliance (see .cursor/rules/tdd.mdc)

Activity

  1. added this to the Backlog milestone on Feb 25, 2026
  2. added
    bug
    area:workspace
    effort:small
    semver:patch
    on Feb 25, 2026
  3. self-assigned this
    on Feb 25, 2026
  4. c-vigo commented on Feb 25, 2026

    @c-vigo
    ContributorAuthor

    Design

    Root Cause

    In `assets/init-workspace.sh`, the rename logic at lines 256-259:

    ```bash
    if [[ -d "$WORKSPACE_DIR/src/template_project" ]]; then
    mv "$WORKSPACE_DIR/src/template_project" "$WORKSPACE_DIR/src/${SHORT_NAME}"
    fi
    ```

    On first run: rsync copies `src/template_project/` from the template, then `mv` renames it to `src/${SHORT_NAME}/`. Correct.

    On second run (with `--force`): rsync re-copies `src/template_project/` because it no longer exists in the workspace (it was renamed). Then `mv` attempts to rename it to `src/${SHORT_NAME}`, but that directory already exists. The `mv` command moves `template_project` inside the existing directory, creating `src/${SHORT_NAME}/template_project/`.

    Fix

    In the rename block, check whether `src/${SHORT_NAME}` already exists. If so, remove the redundant `src/template_project` instead of renaming it. This handles the idempotency case cleanly:

    ```bash
    if [[ -d "$WORKSPACE_DIR/src/template_project" ]]; then
    if [[ -d "$WORKSPACE_DIR/src/${SHORT_NAME}" ]] && [[ "$SHORT_NAME" != "template_project" ]]; then
    echo "Removing duplicate src/template_project (src/${SHORT_NAME} already exists)..."
    rm -rf "$WORKSPACE_DIR/src/template_project"
    else
    echo "Renaming src/template_project to src/${SHORT_NAME}..."
    mv "$WORKSPACE_DIR/src/template_project" "$WORKSPACE_DIR/src/${SHORT_NAME}"
    fi
    fi
    ```

    Testing Strategy

    Add a BATS test to `tests/bats/init-workspace.bats` that verifies the guard clause exists in the script. This matches the existing test pattern (structure/grep tests) since functional testing of init-workspace.sh requires a container environment.

    Scope

    • Files changed: `assets/init-workspace.sh` (fix), `tests/bats/init-workspace.bats` (test), `CHANGELOG.md` (entry)
    • No changes to `install.sh` — the bug is entirely in the container-side script.
  5. c-vigo commented on Feb 25, 2026

    @c-vigo
    ContributorAuthor

    Implementation Plan

    Issue: #197
    Branch: bugfix/197-install-sh-idempotent

    Tasks

    • Task 1: Add BATS test for idempotent rename guard — tests/bats/init-workspace.bats — verify: just test-bats
    • Task 2: Fix rename logic in init-workspace.sh to handle existing destination — assets/init-workspace.sh — verify: just test-bats
    • Task 3: Add CHANGELOG entry — CHANGELOG.md — verify: grep 'idempotent' CHANGELOG.md
  6. c-vigo commented on Feb 25, 2026

    @c-vigo
    ContributorAuthor

    Autonomous Run Complete

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area:workspacebugeffort:smallsemver:patch

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions