From 1c1ed1f3aa2d4169b03034ea474ae62e6bdc35fa Mon Sep 17 00:00:00 2001 From: rob Date: Tue, 17 Nov 2026 12:46:56 +0000 Subject: [PATCH] Implement Forge repository foundation --- .gitignore | 3 + AGENTS.md | 3 + README.md | 6 +- docs/ARCHITECTURE.md | 5 + docs/CURRENT_STATE.md | 3 + docs/DECISIONS.md | 18 +++ docs/HANDOFF.md | 5 + docs/PROJECT_OVERVIEW.md | 3 + docs/TASKS.md | 7 + docs/specifications/integration-contracts.md | 5 + docs/specifications/project-profiles.md | 3 + docs/specifications/skill-contract.md | 5 + docs/specifications/skill-distribution.md | 9 ++ docs/specifications/template-contract.md | 5 + forge/README.md | 3 + profiles/business.yaml | 7 + profiles/personal.yaml | 7 + scripts/install-skills.ps1 | 3 + scripts/install-skills.py | 130 +++++++++++++++++++ scripts/install-skills.sh | 3 + scripts/validate-skills.py | 19 +++ skills/bortstack-context/README.md | 3 + skills/bortstack-contributor/README.md | 3 + skills/bortstack-design/README.md | 3 + skills/bortstack-new/README.md | 3 + templates/flask-react/README.md | 3 + tests/test_installer.py | 79 +++++++++++ 27 files changed, 345 insertions(+), 1 deletion(-) create mode 100644 .gitignore create mode 100644 AGENTS.md create mode 100644 docs/ARCHITECTURE.md create mode 100644 docs/CURRENT_STATE.md create mode 100644 docs/DECISIONS.md create mode 100644 docs/HANDOFF.md create mode 100644 docs/PROJECT_OVERVIEW.md create mode 100644 docs/TASKS.md create mode 100644 docs/specifications/integration-contracts.md create mode 100644 docs/specifications/project-profiles.md create mode 100644 docs/specifications/skill-contract.md create mode 100644 docs/specifications/skill-distribution.md create mode 100644 docs/specifications/template-contract.md create mode 100644 forge/README.md create mode 100644 profiles/business.yaml create mode 100644 profiles/personal.yaml create mode 100644 scripts/install-skills.ps1 create mode 100755 scripts/install-skills.py create mode 100755 scripts/install-skills.sh create mode 100755 scripts/validate-skills.py create mode 100644 skills/bortstack-context/README.md create mode 100644 skills/bortstack-contributor/README.md create mode 100644 skills/bortstack-design/README.md create mode 100644 skills/bortstack-new/README.md create mode 100644 templates/flask-react/README.md create mode 100644 tests/test_installer.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d755d6c --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +__pycache__/ +*.pyc +.test-worktrees/ diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 0000000..c229fcc --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,3 @@ +# Forge repository instructions + +Read `docs/PROJECT_OVERVIEW.md`, `CURRENT_STATE.md`, `DECISIONS.md`, `TASKS.md`, and `HANDOFF.md` before task work. Inspect Git status and relevant code. One accepted implementation task uses a dedicated branch and separate worktree. Preserve unrelated changes and legacy skills. Task IDs use `FORGE-F###`; record implementation, validation, limitations, and handoff. Only mark a task complete after human acceptance. Never commit secrets. Do not modify external projects, production infrastructure, or installed skills as part of foundation work. diff --git a/README.md b/README.md index b1b7161..61f7859 100644 --- a/README.md +++ b/README.md @@ -1 +1,5 @@ -init +# Bortstack Forge + +Forge is a technology-agnostic foundation for project creation and development workflows. [Architecture](docs/ARCHITECTURE.md), [current state](docs/CURRENT_STATE.md), and [tasks](docs/TASKS.md) describe what exists and what is reserved. + +The four canonical skill names are reserved; no skill is implemented yet. `python3 scripts/install-skills.py --list` shows their state. See [skill distribution](docs/specifications/skill-distribution.md) for installation and update procedures. diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md new file mode 100644 index 0000000..636eeab --- /dev/null +++ b/docs/ARCHITECTURE.md @@ -0,0 +1,5 @@ +# Architecture + +`forge/` reserves a framework-independent core. `templates/` contains independent stack-specific packages; `flask-react/` is a reservation only. `skills/` is the canonical source for four future skills. `profiles/` holds minimal business and personal defaults. `scripts/` provides portable user-level skill distribution. `docs/specifications/` defines interfaces; integrations are optional. + +The context skill owns project records, tasks, worktrees, profiles, and design approvals. New delegates lifecycle setup to context. Contributor uses the context lifecycle with Captain/Commander authority and isolated testing. Design uses context for approvals and records. These are contracts, not active skill implementations. diff --git a/docs/CURRENT_STATE.md b/docs/CURRENT_STATE.md new file mode 100644 index 0000000..03da8fd --- /dev/null +++ b/docs/CURRENT_STATE.md @@ -0,0 +1,3 @@ +# Current state + +FORGE-F001 foundation is accepted for integration. The repo initially contained only a five-byte README on `main`; no prior local task or decision files existed. Four skill directories are reserved with README files, so no Forge skills are installable. The installer, validator, specifications, profiles, and automated tests are present. No generator, design integration, or active skill migration has been implemented. Linux tests passed locally; Windows has not been tested. diff --git a/docs/DECISIONS.md b/docs/DECISIONS.md new file mode 100644 index 0000000..4f610f0 --- /dev/null +++ b/docs/DECISIONS.md @@ -0,0 +1,18 @@ +# Architecture decisions + +All five decisions were supplied as approved planning inputs on 2026-11-17. No earlier Forge decision records existed. None supersedes an earlier decision. + +## FORGE-001 — Technology-Agnostic Architecture +Status: Accepted. Date: 2026-11-17. Rationale: project lifecycle must apply across stacks. Consequences: Core has no Flask, React, React Native, or other framework dependency; templates own stack-specific behavior. Supersedes: none. + +## FORGE-002 — Centralised Skill Management +Status: Accepted. Date: 2026-11-17. Rationale: one canonical source avoids divergent skill copies. Consequences: Forge will maintain `bortstack-context`, `bortstack-new`, `bortstack-contributor`, and `bortstack-design`; existing `roborto-*` skills remain until validated migration. Supersedes: none. + +## FORGE-003 — Penpot Integration +Status: Accepted. Date: 2026-11-17. Rationale: Penpot is the selected visual design platform. Consequences: integration is optional and outside Core. Supersedes: none. + +## FORGE-004 — Retrofittable Visual Design Workflow +Status: Accepted. Date: 2026-11-17. Rationale: new and existing projects need the same design lifecycle. Consequences: context owns design references and approvals; design owns Penpot operations and handoffs; implementation needs approved design or recorded override; PitchInvader is the initial pilot. Supersedes: none. + +## FORGE-005 — Business/Personal Profiles +Status: Accepted. Date: 2026-11-17. Rationale: project settings vary by development context. Consequences: profile, ownership, branding, and contributor permissions are distinct; neither profile implies ownership. Supersedes: none. diff --git a/docs/HANDOFF.md b/docs/HANDOFF.md new file mode 100644 index 0000000..77a7704 --- /dev/null +++ b/docs/HANDOFF.md @@ -0,0 +1,5 @@ +# Handoff + +Task: FORGE-F001. Worktree: `/tmp/bortstack-forge-f001`; branch: `codex-forge-f001`. Foundation implementation was accepted by the user for commit and merge into `main`. Run `python3 -m unittest discover -s tests -v`, `python3 scripts/validate-skills.py`, and `python3 scripts/install-skills.py --list`. No Forge skill can currently be installed. Do not migrate or replace existing `roborto-*` skills. Windows installer behavior remains unverified on Windows. Next: review this foundation, then separately authorize the first skill implementation. + +No `testtask` or snapshot adapter was present in this new repository. The installed Roborto context skill normally provisions those for application repositories; Forge has no application runtime or Docker test environment yet. A separate task should resolve a Forge-specific manual-test adapter before treating this repository as enrolled in that full workflow. diff --git a/docs/PROJECT_OVERVIEW.md b/docs/PROJECT_OVERVIEW.md new file mode 100644 index 0000000..b5683e0 --- /dev/null +++ b/docs/PROJECT_OVERVIEW.md @@ -0,0 +1,3 @@ +# Project overview + +Bortstack Forge will manage a framework-independent core, independently maintained application templates, four canonical Codex skills, project profiles, and optional integrations. This repository is the canonical source for future Forge skills. FORGE-F001 establishes contracts and distribution only. Flask/React code remains in its existing source repository. Penpot and repository-provider integrations are optional and absent. diff --git a/docs/TASKS.md b/docs/TASKS.md new file mode 100644 index 0000000..efe94bc --- /dev/null +++ b/docs/TASKS.md @@ -0,0 +1,7 @@ +# Tasks + +## FORGE-F001 — Repository Foundation & Shared Skill Architecture +Status: Complete; human acceptance received 2026-11-17. Approved scope: structure, specifications, portable installer and validation. Acceptance: documented architecture and decisions; safe installer that ignores reserved skills; tests pass; legacy skills and external repositories remain untouched. Task branch/worktree: `codex-forge-f001` at `/tmp/bortstack-forge-f001`. Skill implementation and migration are excluded. + +## Suggested next task +Implement `bortstack-context` as the first canonical skill, including compatibility checks against the existing `roborto-project-context`; authorize and scope separately. diff --git a/docs/specifications/integration-contracts.md b/docs/specifications/integration-contracts.md new file mode 100644 index 0000000..8e975ae --- /dev/null +++ b/docs/specifications/integration-contracts.md @@ -0,0 +1,5 @@ +# Integration and skill interfaces + +`bortstack-context`: project overview/current state, decisions, tasks, handoffs, task-scoped branches/worktrees, design references/approvals, and profile interpretation for new and existing repositories. `bortstack-new`: template selection, generation orchestration, initial configuration and profile, optional Git repository configuration; delegates lifecycle conventions to context. `bortstack-contributor`: onboarding, permitted task creation and implementation, PR preparation, contributor tests and handoff; preserves JJ's task creation, Captain/Commander terminology, isolated branches, and disposable Docker test environments. Manual-testing containers remain available until the contributor is instructed to remove them. `bortstack-design`: visual design orchestration, optional Penpot/MCP operations, concepts, approved handoff, code guidance, and visual QA; delegates task status and approvals to context. Design-dependent implementation needs an approved design or an explicit recorded override. + +Git providers and Penpot are optional adapters. A provider integration must declare authentication, supported operations, failure behavior, and local-only fallback; no provider is assumed. Penpot absence must not block context or non-design tasks. No MCP server or provider integration is configured in this task. diff --git a/docs/specifications/project-profiles.md b/docs/specifications/project-profiles.md new file mode 100644 index 0000000..b10c453 --- /dev/null +++ b/docs/specifications/project-profiles.md @@ -0,0 +1,3 @@ +# Project profile contract + +`profiles/business.yaml` and `profiles/personal.yaml` are flat records with `profile`, `development_context`, `ownership`, `branding`, `contributor_access`, `testing_expectations`, and `deployment_expectations`. The last five values are project-specific placeholders until explicit project configuration is recorded. Business does not imply Bortstack ownership. Profile selection is explicit for new or existing projects; existing repositories are never classified automatically. Profile, owner, brand, and contributor permissions are separate decisions. No inheritance or merge algorithm is defined. diff --git a/docs/specifications/skill-contract.md b/docs/specifications/skill-contract.md new file mode 100644 index 0000000..ffef9b4 --- /dev/null +++ b/docs/specifications/skill-contract.md @@ -0,0 +1,5 @@ +# Skill package contract + +An implemented package lives at `skills//SKILL.md`. Optional `references/`, `scripts/`, and `assets/` directories hold supporting content. The UTF-8 manifest starts with YAML front matter containing unique `name` and nonempty `description`; name must match the directory. A nonempty instruction body is required. The validator checks the minimum metadata and rejects symlinks or likely credential files; it is not a full YAML parser or secret scanner. Reserved directories contain README files only and are not discovered as packages. + +Each skill has one clear responsibility and a distinct activation description. Shared lifecycle rules belong to context, with other skills referring to it rather than copying it. Document required skills and optional integrations in each future manifest. If a required skill is unavailable, report it; do not improvise. Use platform-neutral paths and commands or provide Linux and Windows variants. Repository providers are configurable; GitHub is not assumed. Framework behavior belongs only in a named template. Skills should operate outside Forge where their responsibility allows. diff --git a/docs/specifications/skill-distribution.md b/docs/specifications/skill-distribution.md new file mode 100644 index 0000000..81e7c59 --- /dev/null +++ b/docs/specifications/skill-distribution.md @@ -0,0 +1,9 @@ +# Skill distribution and migration + +Canonical source is `skills/` in this repository. Only directories with valid `SKILL.md` are installable. The current version identifier is the Forge Git commit or task branch revision; there is no independent package version yet. Record the source commit when installing or updating. Installer defaults to `$CODEX_HOME/skills` or `~/.codex/skills`, on Linux and Windows. It copies packages by default, requires no administrator rights for a writable user directory, and never overwrites an existing path. `--link` requests a development symlink and may fail where Windows symlink privileges are unavailable. + +Linux: `python3 scripts/install-skills.py --list`, `--dry-run`, `--install NAME`, or `--all`; `sh scripts/install-skills.sh` forwards the same arguments. Windows PowerShell: `py -3 scripts/install-skills.py --list` or `./scripts/install-skills.ps1 --list`. Use `--dest "path with spaces"` for an isolated skills directory. `--dry-run` plans all implemented skills. Missing and invalid skills fail cleanly. An existing installation conflicts; no force switch exists. + +Update procedure: identify and record the target Forge commit, validate and test that revision, inspect the installed package, move its destination to a user-controlled backup, install the selected new package, restart Codex if needed, test activation and compatibility, then delete the backup only after acceptance. On failure, remove the new package and restore the backup. The installer itself never removes old packages. + +Migration plan: inventory actual installed `roborto-*` directories and internal references on each machine; map `roborto-project-context` to `bortstack-context`, `roborto-new-project` to `bortstack-new`, and `roborto-contributor` to `bortstack-contributor`. `bortstack-design` is new. Preserve context, task, handoff, snapshot, contributor permission, Captain/Commander, and Docker manual-testing behavior. Update internal cross-skill references only after matching implementations exist. Test legacy/new interaction in isolation before exposing both as active, then test Linux installation and JJ's Windows installation separately. Keep old installations until consumer references and user workflows pass; roll back by restoring backups and references. Retire old names only by separate accepted task. FORGE-F001 performs none of this migration. diff --git a/docs/specifications/template-contract.md b/docs/specifications/template-contract.md new file mode 100644 index 0000000..204f635 --- /dev/null +++ b/docs/specifications/template-contract.md @@ -0,0 +1,5 @@ +# Template contract + +A future template descriptor must identify template ID and version, supported project type, configuration variables, generation procedure, dependencies, development commands, validation/test commands, and optional capabilities. It must state platform requirements and how it produces initial context. No descriptor format or generation API is implemented yet. + +The first migration source is the existing `flask-react-auth-base` repository. Its documented `scripts/create-project.sh` accepts a project name, destination, and optional `--git-init`, and refuses existing destinations. It remains external and unchanged. Migration of its code or generator is a separate task. diff --git a/forge/README.md b/forge/README.md new file mode 100644 index 0000000..4e19447 --- /dev/null +++ b/forge/README.md @@ -0,0 +1,3 @@ +# Forge Core + +Reserved for framework-independent orchestration. No generator or runtime code is implemented in FORGE-F001. diff --git a/profiles/business.yaml b/profiles/business.yaml new file mode 100644 index 0000000..5659236 --- /dev/null +++ b/profiles/business.yaml @@ -0,0 +1,7 @@ +profile: business +development_context: business +ownership: project-specific +branding: project-specific +contributor_access: explicit-project-policy +testing_expectations: project-specific +deployment_expectations: project-specific diff --git a/profiles/personal.yaml b/profiles/personal.yaml new file mode 100644 index 0000000..cb628b3 --- /dev/null +++ b/profiles/personal.yaml @@ -0,0 +1,7 @@ +profile: personal +development_context: personal +ownership: project-specific +branding: project-specific +contributor_access: explicit-project-policy +testing_expectations: project-specific +deployment_expectations: project-specific diff --git a/scripts/install-skills.ps1 b/scripts/install-skills.ps1 new file mode 100644 index 0000000..5adbc99 --- /dev/null +++ b/scripts/install-skills.ps1 @@ -0,0 +1,3 @@ +$ErrorActionPreference = 'Stop' +& py -3 (Join-Path $PSScriptRoot 'install-skills.py') @args +exit $LASTEXITCODE diff --git a/scripts/install-skills.py b/scripts/install-skills.py new file mode 100755 index 0000000..560e0d4 --- /dev/null +++ b/scripts/install-skills.py @@ -0,0 +1,130 @@ +#!/usr/bin/env python3 +"""Install implemented Forge skills into a user-level Codex skills directory.""" +import argparse +import os +from pathlib import Path +import re +import shutil +import sys +import tempfile + +ROOT = Path(__file__).resolve().parent.parent +SKILLS = ROOT / 'skills' +RESERVED = {'bortstack-context', 'bortstack-new', 'bortstack-contributor', 'bortstack-design'} +NAME = re.compile(r'^[a-z][a-z0-9-]*$') + + +def manifest(path): + file = path / 'SKILL.md' + if not file.is_file() or file.is_symlink(): + raise ValueError(f'{path.name}: missing SKILL.md') + lines = file.read_text(encoding='utf-8').splitlines() + if not lines or lines[0].strip() != '---': + raise ValueError(f'{path.name}: missing YAML front matter') + try: + end = lines.index('---', 1) + except ValueError: + raise ValueError(f'{path.name}: unclosed YAML front matter') from None + fields = {} + for line in lines[1:end]: + if not line.strip() or line.lstrip().startswith('#'): + continue + if ':' not in line: + raise ValueError(f'{path.name}: invalid metadata line') + key, value = line.split(':', 1) + if key.strip() in fields: + raise ValueError(f'{path.name}: duplicate {key.strip()}') + fields[key.strip()] = value.strip().strip('"\'') + if fields.get('name') != path.name or not NAME.fullmatch(path.name): + raise ValueError(f'{path.name}: name must match directory') + if not fields.get('description'): + raise ValueError(f'{path.name}: missing description') + if not any(line.strip() for line in lines[end + 1:]): + raise ValueError(f'{path.name}: empty skill body') + return fields + + +def discover(): + return sorted(p for p in SKILLS.iterdir() if p.is_dir() and not p.is_symlink() and (p / 'SKILL.md').exists()) + + +def destination(): + codex_home = os.environ.get('CODEX_HOME') + return Path(codex_home).expanduser() / 'skills' if codex_home else Path.home() / '.codex' / 'skills' + + +def safe_source(path): + for entry in path.rglob('*'): + if entry.is_symlink(): + raise ValueError(f'{path.name}: source contains symlink: {entry.relative_to(path)}') + if entry.is_file() and (entry.name.startswith('.env') or entry.suffix.lower() in {'.pem', '.key', '.p12', '.pfx'} or entry.name.lower() in {'id_rsa', 'id_ed25519'}): + raise ValueError(f'{path.name}: possible credential file: {entry.relative_to(path)}') + + +def main(argv=None): + parser = argparse.ArgumentParser(description=__doc__) + group = parser.add_mutually_exclusive_group(required=True) + group.add_argument('--list', action='store_true') + group.add_argument('--dry-run', action='store_true') + group.add_argument('--install', action='append', metavar='NAME') + group.add_argument('--all', action='store_true') + parser.add_argument('--dest', type=Path, default=None, help='skills directory (default: CODEX_HOME/skills or ~/.codex/skills)') + parser.add_argument('--link', action='store_true', help='development symlinks instead of copies') + args = parser.parse_args(argv) + dest = (args.dest or destination()).expanduser() + found = discover() + valid = {} + errors = [] + for path in found: + try: + manifest(path) + safe_source(path) + valid[path.name] = path + except (ValueError, UnicodeError) as exc: + errors.append(str(exc)) + if args.list: + for name in sorted(RESERVED | set(valid)): + print(f'{name}: {"implemented" if name in valid else "reserved"} -> {dest / name}') + for error in errors: + print(f'INVALID: {error}', file=sys.stderr) + return 1 if errors else 0 + requested = list(valid) if args.all or args.dry_run else args.install + problems = list(errors) + for name in requested: + if name not in valid: + problems.append(f'{name}: missing, reserved, or invalid skill') + if problems: + for problem in problems: + print(f'ERROR: {problem}', file=sys.stderr) + return 1 + conflicts = [name for name in requested if (dest / name).exists() or (dest / name).is_symlink()] + for name in requested: + print(f'{"CONFLICT" if name in conflicts else "PLAN" if args.dry_run else "INSTALL"}: {name} -> {dest / name}') + if conflicts: + print('Existing installations are never overwritten. Remove or move a destination explicitly before retrying.', file=sys.stderr) + return 1 + if args.dry_run: + return 0 + dest.mkdir(parents=True, exist_ok=True) + for name in requested: + target = dest / name + if args.link: + try: + target.symlink_to(valid[name], target_is_directory=True) + except OSError as exc: + print(f'ERROR: symlink failed for {name}: {exc}', file=sys.stderr) + return 1 + else: + temp = Path(tempfile.mkdtemp(prefix=f'.{name}-', dir=dest)) + try: + shutil.copytree(valid[name], temp, dirs_exist_ok=True, symlinks=False) + temp.rename(target) + except OSError as exc: + shutil.rmtree(temp, ignore_errors=True) + print(f'ERROR: installation failed for {name}: {exc}', file=sys.stderr) + return 1 + return 0 + + +if __name__ == '__main__': + sys.exit(main()) diff --git a/scripts/install-skills.sh b/scripts/install-skills.sh new file mode 100755 index 0000000..65ca04b --- /dev/null +++ b/scripts/install-skills.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -eu +exec python3 "$(dirname "$0")/install-skills.py" "$@" diff --git a/scripts/validate-skills.py b/scripts/validate-skills.py new file mode 100755 index 0000000..d71642f --- /dev/null +++ b/scripts/validate-skills.py @@ -0,0 +1,19 @@ +#!/usr/bin/env python3 +"""Validate implemented canonical skill packages.""" +from importlib.machinery import SourceFileLoader +from pathlib import Path +import sys + +installer = SourceFileLoader('forge_installer', str(Path(__file__).with_name('install-skills.py'))).load_module() +errors = [] +for path in installer.discover(): + try: + installer.manifest(path) + installer.safe_source(path) + print(f'VALID: {path.name}') + except (ValueError, UnicodeError) as exc: + errors.append(str(exc)) +for error in errors: + print(f'INVALID: {error}', file=sys.stderr) +print(f'{len(installer.discover()) - len(errors)} implemented skill(s); {len(installer.RESERVED - {p.name for p in installer.discover()})} reserved') +sys.exit(bool(errors)) diff --git a/skills/bortstack-context/README.md b/skills/bortstack-context/README.md new file mode 100644 index 0000000..cb7e449 --- /dev/null +++ b/skills/bortstack-context/README.md @@ -0,0 +1,3 @@ +# bortstack-context + +Reserved for a separate implementation task. No SKILL.md is provided. diff --git a/skills/bortstack-contributor/README.md b/skills/bortstack-contributor/README.md new file mode 100644 index 0000000..fdde90b --- /dev/null +++ b/skills/bortstack-contributor/README.md @@ -0,0 +1,3 @@ +# bortstack-contributor + +Reserved for a separate implementation task. No SKILL.md is provided. diff --git a/skills/bortstack-design/README.md b/skills/bortstack-design/README.md new file mode 100644 index 0000000..cec6364 --- /dev/null +++ b/skills/bortstack-design/README.md @@ -0,0 +1,3 @@ +# bortstack-design + +Reserved for a separate implementation task. No SKILL.md is provided. diff --git a/skills/bortstack-new/README.md b/skills/bortstack-new/README.md new file mode 100644 index 0000000..37bcfa7 --- /dev/null +++ b/skills/bortstack-new/README.md @@ -0,0 +1,3 @@ +# bortstack-new + +Reserved for a separate implementation task. No SKILL.md is provided. diff --git a/templates/flask-react/README.md b/templates/flask-react/README.md new file mode 100644 index 0000000..7797f54 --- /dev/null +++ b/templates/flask-react/README.md @@ -0,0 +1,3 @@ +# Flask/React template reservation + +Initial migration source: `/home/rob/projects/flask-react-auth-base` in the current development environment. Its `scripts/create-project.sh` generates a clean project copy and optionally initializes Git. This source has not been moved, copied, or rewritten here. The path is discovery evidence, not a portable dependency. See the [template contract](../../docs/specifications/template-contract.md). diff --git a/tests/test_installer.py b/tests/test_installer.py new file mode 100644 index 0000000..5e9d2b4 --- /dev/null +++ b/tests/test_installer.py @@ -0,0 +1,79 @@ +import os +from pathlib import Path +import shutil +import subprocess +import sys +import tempfile +import unittest + +SCRIPT = Path(__file__).resolve().parents[1] / 'scripts' / 'install-skills.py' + + +class InstallerTests(unittest.TestCase): + def setUp(self): + self.tmp = tempfile.TemporaryDirectory(prefix='forge path with spaces ') + self.addCleanup(self.tmp.cleanup) + self.root = Path(self.tmp.name) / 'repo with spaces' + (self.root / 'scripts').mkdir(parents=True) + (self.root / 'skills').mkdir() + shutil.copy2(SCRIPT, self.root / 'scripts' / SCRIPT.name) + self.dest = Path(self.tmp.name) / 'Codex skills with spaces' + self.legacy = self.dest / 'roborto-project-context' + self.legacy.mkdir(parents=True) + (self.legacy / 'SKILL.md').write_text('legacy untouched') + + def skill(self, name='bortstack-context', description='Context workflow'): + path = self.root / 'skills' / name + path.mkdir() + (path / 'SKILL.md').write_text(f'---\nname: {name}\ndescription: {description}\n---\n\n# Instructions\n', encoding='utf-8') + return path + + def run_cli(self, *args): + return subprocess.run([sys.executable, str(self.root / 'scripts' / SCRIPT.name), *args, '--dest', str(self.dest)], capture_output=True, text=True) + + def test_reserved_not_discovered(self): + (self.root / 'skills' / 'bortstack-design').mkdir() + (self.root / 'skills' / 'bortstack-design' / 'README.md').write_text('reserved') + result = self.run_cli('--list') + self.assertEqual(result.returncode, 0) + self.assertIn('bortstack-design: reserved', result.stdout) + self.assertNotIn('bortstack-design: implemented', result.stdout) + self.assertNotIn('roborto-project-context:', result.stdout) + + def test_dry_run_and_copy_with_spaces_and_legacy_preserved(self): + self.skill() + dry = self.run_cli('--dry-run') + self.assertEqual(dry.returncode, 0, dry.stderr) + self.assertFalse((self.dest / 'bortstack-context').exists()) + installed = self.run_cli('--install', 'bortstack-context') + self.assertEqual(installed.returncode, 0, installed.stderr) + self.assertTrue((self.dest / 'bortstack-context' / 'SKILL.md').exists()) + self.assertEqual((self.legacy / 'SKILL.md').read_text(), 'legacy untouched') + + def test_conflict_refuses_overwrite(self): + self.skill() + target = self.dest / 'bortstack-context' + target.mkdir() + (target / 'SKILL.md').write_text('existing') + result = self.run_cli('--install', 'bortstack-context') + self.assertNotEqual(result.returncode, 0) + self.assertIn('CONFLICT', result.stdout) + self.assertEqual((target / 'SKILL.md').read_text(), 'existing') + + def test_missing_and_invalid_rejected(self): + self.assertNotEqual(self.run_cli('--install', 'bortstack-context').returncode, 0) + self.skill(description='') + invalid = self.run_cli('--install', 'bortstack-context') + self.assertNotEqual(invalid.returncode, 0) + self.assertIn('missing description', invalid.stderr) + + def test_credential_rejected(self): + path = self.skill() + (path / '.env').write_text('SECRET=x') + result = self.run_cli('--dry-run') + self.assertNotEqual(result.returncode, 0) + self.assertIn('credential', result.stderr) + + +if __name__ == '__main__': + unittest.main()