fix(core): add VERSION file handling and comprehensive test coverage

This commit fixes version management and argument parsing issues across
both Windows and Linux/macOS platforms, achieving 100% test coverage.

Changes:
- Add VERSION file installation to both installers (install.sh, install.ps1)
- Fix version/help command detection when using 'powershell -File' syntax
- Rename PowerShell param from $Profile to $ProfileOrFlag for clarity
- Add $FirstArg detection to check both ProfileOrFlag and RemainingArgs
- Create comprehensive edge case test suites for both platforms:
  * tests/edge-cases.ps1 - 31 tests for Windows (100% pass)
  * tests/edge-cases.sh - 37 tests for Linux/macOS (100% pass)
- Fix multiline regex matching in tests for error messages
- Update test expectations to match platform-specific behavior
- Reorganize project structure:
  * Move installers to installers/ directory
  * Add scripts/ directory for version management
  * Add config/ directory for configuration templates
  * Add docs/ directory for documentation

Test Results:
- Windows (PowerShell): 31/31 tests passing (100%)
- Linux/macOS (Bash): 37/37 tests passing (100%)

Breaking Changes: None
- Installers moved but GitHub URLs updated in README files
- All existing functionality preserved

Co-authored-by: Claude Code <claude@anthropic.com>
This commit is contained in:
kaitranntt
2025-11-02 20:27:45 -05:00
co-authored by Claude Code
parent 7bd2e9e4ba
commit e9eb215d1f
24 changed files with 2392 additions and 484 deletions
+112
View File
@@ -0,0 +1,112 @@
#!/usr/bin/env bash
# Bump CCS version
# Usage: ./scripts/bump-version.sh [major|minor|patch]
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
CCS_DIR="$(dirname "$SCRIPT_DIR")"
VERSION_FILE="$CCS_DIR/VERSION"
# Check VERSION file exists
if [[ ! -f "$VERSION_FILE" ]]; then
echo "✗ Error: VERSION file not found at $VERSION_FILE"
exit 1
fi
# Read current version
CURRENT_VERSION=$(cat "$VERSION_FILE")
echo "Current version: $CURRENT_VERSION"
# Parse version
if [[ ! "$CURRENT_VERSION" =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then
echo "✗ Error: Invalid version format in VERSION file"
echo "Expected: MAJOR.MINOR.PATCH (e.g., 1.2.3)"
exit 1
fi
MAJOR="${BASH_REMATCH[1]}"
MINOR="${BASH_REMATCH[2]}"
PATCH="${BASH_REMATCH[3]}"
# Determine bump type
BUMP_TYPE="${1:-patch}"
case "$BUMP_TYPE" in
major)
MAJOR=$((MAJOR + 1))
MINOR=0
PATCH=0
;;
minor)
MINOR=$((MINOR + 1))
PATCH=0
;;
patch)
PATCH=$((PATCH + 1))
;;
*)
echo "✗ Error: Invalid bump type '$BUMP_TYPE'"
echo "Usage: $0 [major|minor|patch]"
exit 1
;;
esac
NEW_VERSION="$MAJOR.$MINOR.$PATCH"
echo "New version: $NEW_VERSION"
echo ""
echo "This will:"
echo " 1. Update VERSION file"
echo " 2. Update installers/install.sh (hardcoded version)"
echo " 3. Update installers/install.ps1 (hardcoded version)"
echo " 4. Create git tag v$NEW_VERSION (if in git repo)"
echo ""
read -p "Continue? (y/N) " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo "Cancelled."
exit 0
fi
# Update VERSION file
echo "$NEW_VERSION" > "$VERSION_FILE"
echo "✓ Updated VERSION file to $NEW_VERSION"
# Update installers/install.sh
INSTALL_SH="$CCS_DIR/installers/install.sh"
if [[ -f "$INSTALL_SH" ]]; then
sed -i.bak "s/^CCS_VERSION=\".*\"/CCS_VERSION=\"$NEW_VERSION\"/" "$INSTALL_SH"
rm -f "$INSTALL_SH.bak"
echo "✓ Updated installers/install.sh"
else
echo "⚠ installers/install.sh not found, skipping"
fi
# Update installers/install.ps1
INSTALL_PS1="$CCS_DIR/installers/install.ps1"
if [[ -f "$INSTALL_PS1" ]]; then
sed -i.bak "s/^\$CcsVersion = \".*\"/\$CcsVersion = \"$NEW_VERSION\"/" "$INSTALL_PS1"
rm -f "$INSTALL_PS1.bak"
echo "✓ Updated installers/install.ps1"
else
echo "⚠ installers/install.ps1 not found, skipping"
fi
# Create git tag if in repo
if git rev-parse --git-dir > /dev/null 2>&1; then
if git tag -a "v$NEW_VERSION" -m "Release v$NEW_VERSION"; then
echo "✓ Created git tag v$NEW_VERSION"
echo ""
echo "Next steps:"
echo " git push origin v$NEW_VERSION"
else
echo "⚠ Failed to create git tag (may already exist)"
fi
else
echo " Not in git repository, skipping tag creation"
fi
echo ""
echo "✓ Version bumped to $NEW_VERSION"
+16
View File
@@ -0,0 +1,16 @@
#!/usr/bin/env bash
# Get current CCS version
# Usage: ./scripts/get-version.sh
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
CCS_DIR="$(dirname "$SCRIPT_DIR")"
VERSION_FILE="$CCS_DIR/VERSION"
if [[ -f "$VERSION_FILE" ]]; then
cat "$VERSION_FILE"
else
echo "unknown"
exit 1
fi
+46
View File
@@ -0,0 +1,46 @@
export default {
async fetch(request) {
const url = new URL(request.url);
// Detect platform from User-Agent header
const userAgent = request.headers.get('user-agent') || '';
const isWindows = userAgent.includes('Windows') || userAgent.includes('Win32');
const isPowerShell = userAgent.includes('PowerShell') || userAgent.includes('pwsh');
// Smart routing with platform detection
let filePath;
if (url.pathname === '/install' || url.pathname === '/install.sh') {
filePath = (isWindows && isPowerShell) ? 'installers/install.ps1' : 'installers/install.sh';
} else if (url.pathname === '/install.ps1') {
filePath = 'installers/install.ps1';
} else if (url.pathname === '/uninstall' || url.pathname === '/uninstall.sh') {
filePath = (isWindows && isPowerShell) ? 'installers/uninstall.ps1' : 'installers/uninstall.sh';
} else if (url.pathname === '/uninstall.ps1') {
filePath = 'installers/uninstall.ps1';
} else {
return new Response('Not Found', { status: 404 });
}
try {
const githubUrl = `https://raw.githubusercontent.com/kaitranntt/ccs/main/${filePath}`;
const response = await fetch(githubUrl);
if (!response.ok) {
return new Response('File not found on GitHub', { status: 404 });
}
const contentType = filePath.endsWith('.ps1')
? 'text/plain; charset=utf-8'
: 'text/x-shellscript; charset=utf-8';
return new Response(response.body, {
headers: {
'Content-Type': contentType,
'Cache-Control': 'public, max-age=300'
}
});
} catch (error) {
return new Response('Server Error', { status: 500 });
}
}
};