fix: resolve three critical bugs from GitHub issue tracker

Fix #684: Prevent Windows reserved filename creation
- Add sanitizeFilename() utility to detect and prefix Windows reserved names
  (NUL, CON, PRN, AUX, COM1-9, LPT1-9)
- Apply sanitization to save-image route to prevent "nul" file creation
- Add 23 comprehensive tests for filename sanitization edge cases

Fix #576: Detect actual dev server port from output
- Parse stdout/stderr for real server URLs (Vite, Next.js, generic formats)
- Update server URL when detected instead of using allocated PORT
- Emit dev-server:url-detected event for frontend updates
- Add 6 tests for URL detection patterns

Fix #193: Commit only feature-specific changes
- Change from 'git add -A' to branch-aware file staging
- Use git diff to find files changed on feature branch only
- Prevent committing unrelated changes from other features
- Maintain backward compatibility with main branch workflow

All fixes include comprehensive tests and maintain backward compatibility.
Test results: 1,968 tests passed (547 package + 1,421 server tests)
This commit is contained in:
DhanushSantosh
2026-02-05 10:42:56 +05:30
parent 63cae19aec
commit 84570842d3
7 changed files with 461 additions and 5 deletions

View File

@@ -2662,8 +2662,64 @@ Address the follow-up instructions above. Review the previous work and make the
)}\n\nImplemented by Automaker auto-mode`
: `feat: Feature ${featureId}`;
// Stage and commit
await execAsync('git add -A', { cwd: workDir });
// Determine which files to stage
// For feature branches, only stage files changed on this branch to avoid committing unrelated changes
let filesToStage: string[] = [];
try {
// Get the current branch
const { stdout: currentBranch } = await execAsync('git rev-parse --abbrev-ref HEAD', {
cwd: workDir,
});
const branch = currentBranch.trim();
// Get the base branch (usually main/master)
const { stdout: baseBranchOutput } = await execAsync(
'git symbolic-ref refs/remotes/origin/HEAD 2>/dev/null || echo "refs/remotes/origin/main"',
{ cwd: workDir }
);
const baseBranch = baseBranchOutput.trim().replace('refs/remotes/origin/', '');
// If we're on a feature branch (not the base branch), only stage files changed on this branch
if (branch !== baseBranch && feature?.branchName) {
try {
// Get files changed on this branch compared to base
const { stdout: branchFiles } = await execAsync(
`git diff --name-only ${baseBranch}...HEAD`,
{ cwd: workDir }
);
if (branchFiles.trim()) {
filesToStage = branchFiles.trim().split('\n').filter(Boolean);
logger.info(`Staging ${filesToStage.length} files changed on branch ${branch}`);
}
} catch (diffError) {
// If diff fails (e.g., base branch doesn't exist), fall back to staging all changes
logger.warn(`Could not diff against base branch, staging all changes: ${diffError}`);
filesToStage = [];
}
}
} catch (error) {
logger.warn(`Could not determine branch-specific files: ${error}`);
}
// Stage files
if (filesToStage.length > 0) {
// Stage only the specific files changed on this branch
for (const file of filesToStage) {
try {
await execAsync(`git add "${file.replace(/"/g, '\\"')}"`, { cwd: workDir });
} catch (error) {
logger.warn(`Failed to stage file ${file}: ${error}`);
}
}
} else {
// Fallback: stage all changes (original behavior)
// This happens for main branch features or when branch detection fails
await execAsync('git add -A', { cwd: workDir });
}
// Commit
await execAsync(`git commit -m "${commitMessage.replace(/"/g, '\\"')}"`, {
cwd: workDir,
});