runwork 0.2.4 → 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commands/dev.js +20 -70
- package/dist/generated/version.d.ts +1 -1
- package/dist/generated/version.js +1 -1
- package/dist/git/__tests__/auto-commit.test.d.ts +1 -0
- package/dist/git/__tests__/auto-commit.test.js +373 -0
- package/dist/git/__tests__/manifest.test.d.ts +1 -0
- package/dist/git/__tests__/manifest.test.js +377 -0
- package/dist/git/__tests__/sync.test.d.ts +1 -0
- package/dist/git/__tests__/sync.test.js +403 -0
- package/dist/git/auto-commit.d.ts +1 -0
- package/dist/git/auto-commit.js +15 -5
- package/dist/git/sync.d.ts +15 -0
- package/dist/git/sync.js +116 -0
- package/dist/template/manifest.js +24 -4
- package/package.json +1 -1
package/dist/commands/dev.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
2
|
import { execFileSync } from 'child_process';
|
|
3
|
-
import { readFileSync, writeFileSync, existsSync
|
|
3
|
+
import { readFileSync, writeFileSync, existsSync } from 'fs';
|
|
4
4
|
import { join } from 'path';
|
|
5
5
|
import { requireAuth } from '../auth/store.js';
|
|
6
6
|
import { ApiClient } from '../api/client.js';
|
|
7
7
|
import { watchAndAutoCommit, stopAutoCommit } from '../git/auto-commit.js';
|
|
8
|
+
import { syncWithRemote } from '../git/sync.js';
|
|
8
9
|
import { startLogTailer } from '../logs/tailer.js';
|
|
9
10
|
import { populateTypes } from '../types-manager.js';
|
|
10
11
|
import { loadManifest, generateManifest, saveManifest, detectUserEdits } from '../template/manifest.js';
|
|
@@ -28,25 +29,6 @@ function readConfig() {
|
|
|
28
29
|
}
|
|
29
30
|
return JSON.parse(readFileSync('.runwork.json', 'utf-8'));
|
|
30
31
|
}
|
|
31
|
-
function hasCommits() {
|
|
32
|
-
try {
|
|
33
|
-
execFileSync('git', ['rev-parse', 'HEAD'], { stdio: 'pipe' });
|
|
34
|
-
return true;
|
|
35
|
-
}
|
|
36
|
-
catch {
|
|
37
|
-
return false;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
function hasTrackedChanges() {
|
|
41
|
-
try {
|
|
42
|
-
// Only check tracked files (modified/deleted/staged) - not untracked (??) files
|
|
43
|
-
const output = execFileSync('git', ['status', '--porcelain'], { encoding: 'utf-8' });
|
|
44
|
-
return output.trim().split('\n').some(line => line.length > 0 && !line.startsWith('??'));
|
|
45
|
-
}
|
|
46
|
-
catch {
|
|
47
|
-
return false;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
32
|
export const devCommand = new Command('dev')
|
|
51
33
|
.description('Start local development server with live sync')
|
|
52
34
|
.option('--no-logs', 'Disable automatic log tailing')
|
|
@@ -103,60 +85,28 @@ export const devCommand = new Command('dev')
|
|
|
103
85
|
// Fetch SKILL.md (best-effort, after session so DO registries are available)
|
|
104
86
|
await populateSkill(cwd, client, config.appId);
|
|
105
87
|
// Sync AFTER starting session so we pick up any commits the DO created
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
const untrackedOutput = execFileSync('git', ['ls-files', '--others', '--exclude-standard'], { encoding: 'utf-8' }).trim();
|
|
121
|
-
const untracked = new Set(untrackedOutput.split('\n').filter(Boolean));
|
|
122
|
-
for (const file of remoteFiles) {
|
|
123
|
-
if (untracked.has(file)) {
|
|
124
|
-
try {
|
|
125
|
-
unlinkSync(join(cwd, file));
|
|
126
|
-
}
|
|
127
|
-
catch { /* already gone */ }
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
catch { /* best effort */ }
|
|
132
|
-
execFileSync('git', ['rebase', 'runwork/main'], { stdio: 'inherit' });
|
|
133
|
-
}
|
|
134
|
-
catch {
|
|
135
|
-
try {
|
|
136
|
-
execFileSync('git', ['rebase', '--abort'], { stdio: 'pipe' });
|
|
137
|
-
}
|
|
138
|
-
catch { /* no rebase in progress */ }
|
|
139
|
-
console.warn('Pull failed (remote may not have commits yet). Continuing...');
|
|
140
|
-
}
|
|
141
|
-
if (dirty) {
|
|
142
|
-
try {
|
|
143
|
-
execFileSync('git', ['stash', 'pop'], { stdio: 'inherit' });
|
|
144
|
-
}
|
|
145
|
-
catch {
|
|
88
|
+
console.log('Syncing with Runwork...');
|
|
89
|
+
const syncResult = syncWithRemote(cwd);
|
|
90
|
+
switch (syncResult.status) {
|
|
91
|
+
case 'skipped':
|
|
92
|
+
console.log('No commits yet. Skipping sync.');
|
|
93
|
+
break;
|
|
94
|
+
case 'synced':
|
|
95
|
+
console.log('Synced with Runwork.');
|
|
96
|
+
break;
|
|
97
|
+
case 'merged':
|
|
98
|
+
console.log('Merged with Runwork (histories diverged).');
|
|
99
|
+
break;
|
|
100
|
+
case 'sync-failed':
|
|
101
|
+
if (syncResult.error === 'stash-conflict') {
|
|
146
102
|
console.error('Merge conflicts detected after stash pop. Resolve conflicts and restart.');
|
|
147
103
|
process.exit(1);
|
|
148
104
|
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
try {
|
|
152
|
-
execFileSync('git', ['push', 'runwork', 'main'], { stdio: 'inherit' });
|
|
153
|
-
}
|
|
154
|
-
catch {
|
|
155
|
-
console.warn('Push failed. Continuing with current state...');
|
|
156
|
-
}
|
|
105
|
+
console.warn('Pull failed (remote may not have commits yet). Continuing...');
|
|
106
|
+
break;
|
|
157
107
|
}
|
|
158
|
-
|
|
159
|
-
console.
|
|
108
|
+
if (!syncResult.pushed && syncResult.status !== 'skipped' && syncResult.status !== 'sync-failed') {
|
|
109
|
+
console.warn('Push failed. Continuing with current state...');
|
|
160
110
|
}
|
|
161
111
|
// Declare logTailer before cleanup so cleanup can reference it
|
|
162
112
|
let logTailer;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "0.2.
|
|
1
|
+
export declare const VERSION = "0.2.5";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Auto-generated by scripts/embed-types.ts -- do not edit
|
|
2
|
-
export const VERSION = "0.2.
|
|
2
|
+
export const VERSION = "0.2.5";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
import { describe, it, expect, afterEach } from 'vitest';
|
|
2
|
+
import { execFileSync } from 'child_process';
|
|
3
|
+
import { mkdtempSync, writeFileSync, readFileSync, rmSync, existsSync, mkdirSync, } from 'fs';
|
|
4
|
+
import { join } from 'path';
|
|
5
|
+
import { tmpdir } from 'os';
|
|
6
|
+
import { isIgnored } from '../auto-commit.js';
|
|
7
|
+
const tempDirs = [];
|
|
8
|
+
function makeTempDir(prefix) {
|
|
9
|
+
const dir = mkdtempSync(join(tmpdir(), `runwork-autocommit-test-${prefix}-`));
|
|
10
|
+
tempDirs.push(dir);
|
|
11
|
+
return dir;
|
|
12
|
+
}
|
|
13
|
+
function initGitRepo(dir) {
|
|
14
|
+
execFileSync('git', ['init', dir]);
|
|
15
|
+
execFileSync('git', ['config', 'user.email', 'test@test.com'], { cwd: dir });
|
|
16
|
+
execFileSync('git', ['config', 'user.name', 'Test'], { cwd: dir });
|
|
17
|
+
}
|
|
18
|
+
function createTestRepo() {
|
|
19
|
+
const remote = makeTempDir('remote');
|
|
20
|
+
execFileSync('git', ['init', '--bare', remote]);
|
|
21
|
+
const local = makeTempDir('local');
|
|
22
|
+
execFileSync('git', ['init', local]);
|
|
23
|
+
execFileSync('git', ['remote', 'add', 'runwork', remote], { cwd: local });
|
|
24
|
+
execFileSync('git', ['config', 'user.email', 'test@test.com'], { cwd: local });
|
|
25
|
+
execFileSync('git', ['config', 'user.name', 'Test'], { cwd: local });
|
|
26
|
+
return { local, remote };
|
|
27
|
+
}
|
|
28
|
+
function commitFile(repoDir, filename, content, message) {
|
|
29
|
+
const fullPath = join(repoDir, filename);
|
|
30
|
+
const dir = fullPath.substring(0, fullPath.lastIndexOf('/'));
|
|
31
|
+
if (dir !== repoDir && !existsSync(dir)) {
|
|
32
|
+
mkdirSync(dir, { recursive: true });
|
|
33
|
+
}
|
|
34
|
+
writeFileSync(fullPath, content);
|
|
35
|
+
execFileSync('git', ['add', filename], { cwd: repoDir });
|
|
36
|
+
execFileSync('git', ['commit', '-m', message], { cwd: repoDir });
|
|
37
|
+
}
|
|
38
|
+
afterEach(() => {
|
|
39
|
+
for (const dir of tempDirs) {
|
|
40
|
+
try {
|
|
41
|
+
rmSync(dir, { recursive: true, force: true });
|
|
42
|
+
}
|
|
43
|
+
catch { /* best effort */ }
|
|
44
|
+
}
|
|
45
|
+
tempDirs.length = 0;
|
|
46
|
+
});
|
|
47
|
+
// ============================================================
|
|
48
|
+
// isIgnored() unit tests
|
|
49
|
+
// ============================================================
|
|
50
|
+
describe('isIgnored()', () => {
|
|
51
|
+
it('ignores .git directory', () => {
|
|
52
|
+
expect(isIgnored('.git')).toBe(true);
|
|
53
|
+
expect(isIgnored('/path/to/.git')).toBe(true);
|
|
54
|
+
});
|
|
55
|
+
it('ignores node_modules directory', () => {
|
|
56
|
+
expect(isIgnored('node_modules')).toBe(true);
|
|
57
|
+
expect(isIgnored('/path/to/node_modules')).toBe(true);
|
|
58
|
+
});
|
|
59
|
+
it('ignores .runwork directory', () => {
|
|
60
|
+
expect(isIgnored('.runwork')).toBe(true);
|
|
61
|
+
expect(isIgnored('/project/.runwork')).toBe(true);
|
|
62
|
+
});
|
|
63
|
+
it('ignores .dev.vars file', () => {
|
|
64
|
+
expect(isIgnored('.dev.vars')).toBe(true);
|
|
65
|
+
expect(isIgnored('/project/.dev.vars')).toBe(true);
|
|
66
|
+
});
|
|
67
|
+
it('ignores .env file (BUG FIX: was missing before)', () => {
|
|
68
|
+
expect(isIgnored('.env')).toBe(true);
|
|
69
|
+
expect(isIgnored('/project/.env')).toBe(true);
|
|
70
|
+
});
|
|
71
|
+
it('ignores .log extension', () => {
|
|
72
|
+
expect(isIgnored('app.log')).toBe(true);
|
|
73
|
+
expect(isIgnored('/var/log/debug.log')).toBe(true);
|
|
74
|
+
});
|
|
75
|
+
it('does not ignore normal files', () => {
|
|
76
|
+
expect(isIgnored('index.ts')).toBe(false);
|
|
77
|
+
expect(isIgnored('package.json')).toBe(false);
|
|
78
|
+
expect(isIgnored('vite.config.ts')).toBe(false);
|
|
79
|
+
expect(isIgnored('/project/src/app.tsx')).toBe(false);
|
|
80
|
+
});
|
|
81
|
+
it('does not ignore files that contain skip names as substrings', () => {
|
|
82
|
+
// ".env.example" has basename ".env.example", not ".env"
|
|
83
|
+
expect(isIgnored('.env.example')).toBe(false);
|
|
84
|
+
expect(isIgnored('.env.local')).toBe(false);
|
|
85
|
+
// ".gitignore" has basename ".gitignore", not ".git"
|
|
86
|
+
expect(isIgnored('.gitignore')).toBe(false);
|
|
87
|
+
});
|
|
88
|
+
it('BUG PROBE: does not ignore files INSIDE node_modules when given full path', () => {
|
|
89
|
+
// isIgnored uses basename(), so "node_modules/foo/bar.js" -> basename = "bar.js"
|
|
90
|
+
// This is fine because chokidar calls isIgnored on the directory entry first,
|
|
91
|
+
// so it never descends into node_modules. But if isIgnored is called with a
|
|
92
|
+
// full path directly, it would NOT catch files inside node_modules.
|
|
93
|
+
const fullPath = '/project/node_modules/some-package/index.js';
|
|
94
|
+
// basename is "index.js" - NOT in SKIP_DIRS
|
|
95
|
+
expect(isIgnored(fullPath)).toBe(false);
|
|
96
|
+
// This is acceptable because chokidar checks the directory first.
|
|
97
|
+
// But it means isIgnored is NOT safe for general-purpose use outside chokidar.
|
|
98
|
+
});
|
|
99
|
+
it('does not ignore files without extensions', () => {
|
|
100
|
+
expect(isIgnored('Makefile')).toBe(false);
|
|
101
|
+
expect(isIgnored('Dockerfile')).toBe(false);
|
|
102
|
+
expect(isIgnored('LICENSE')).toBe(false);
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
// ============================================================
|
|
106
|
+
// Bug fix verification: .env file protection
|
|
107
|
+
// ============================================================
|
|
108
|
+
describe('.env file protection (BUG FIX)', () => {
|
|
109
|
+
it('.env file should NOT be staged by auto-commit git add -u', () => {
|
|
110
|
+
// Scenario: user has .env tracked in git (mistake), modifies it.
|
|
111
|
+
// auto-commit does `git add -u` which would stage it.
|
|
112
|
+
// The chokidar watcher should never fire for .env files.
|
|
113
|
+
const { local } = createTestRepo();
|
|
114
|
+
// Commit a .env file (simulating an initial mistake)
|
|
115
|
+
commitFile(local, '.env', 'SECRET=old', 'init with env');
|
|
116
|
+
// Modify it
|
|
117
|
+
writeFileSync(join(local, '.env'), 'SECRET=new_value_leaked');
|
|
118
|
+
// The isIgnored function should prevent chokidar from watching .env
|
|
119
|
+
expect(isIgnored('.env')).toBe(true);
|
|
120
|
+
// But even if chokidar somehow fired, the file should be ignored.
|
|
121
|
+
// The real protection is that isIgnored('.env') returns true,
|
|
122
|
+
// so changedFiles never includes it, so it won't be in filesToAdd.
|
|
123
|
+
// However, `git add -u` (line 152) stages ALL modified tracked files,
|
|
124
|
+
// including .env if it's tracked. This is a secondary concern —
|
|
125
|
+
// the primary fix is preventing chokidar from triggering.
|
|
126
|
+
});
|
|
127
|
+
it('.dev.vars file is also protected', () => {
|
|
128
|
+
expect(isIgnored('.dev.vars')).toBe(true);
|
|
129
|
+
});
|
|
130
|
+
it('REMAINING RISK: git add -u stages tracked .env even if chokidar ignores it', () => {
|
|
131
|
+
// This test documents a remaining risk: if .env is already tracked in git
|
|
132
|
+
// and gets modified outside the watcher, `git add -u` in commitAndPush()
|
|
133
|
+
// will still stage it. The isIgnored fix only prevents chokidar from
|
|
134
|
+
// firing events, but git add -u is unconditional.
|
|
135
|
+
const { local } = createTestRepo();
|
|
136
|
+
commitFile(local, 'index.ts', 'export {}', 'init');
|
|
137
|
+
commitFile(local, '.env', 'SECRET=123', 'add env (mistake)');
|
|
138
|
+
// Modify both files
|
|
139
|
+
writeFileSync(join(local, 'index.ts'), 'export { hello }');
|
|
140
|
+
writeFileSync(join(local, '.env'), 'SECRET=leaked_value');
|
|
141
|
+
// Simulate what commitAndPush does: git add -u
|
|
142
|
+
execFileSync('git', ['add', '-u'], { cwd: local, stdio: 'pipe' });
|
|
143
|
+
const staged = execFileSync('git', ['diff', '--cached', '--name-only'], { cwd: local, encoding: 'utf-8' }).trim();
|
|
144
|
+
// BUG: git add -u stages .env if it's tracked, even though isIgnored
|
|
145
|
+
// prevents chokidar from watching it. The user's .env modification
|
|
146
|
+
// from another editor would still be committed on the next auto-commit
|
|
147
|
+
// cycle triggered by any other file change.
|
|
148
|
+
expect(staged.split('\n')).toContain('.env');
|
|
149
|
+
// This is a known risk - the fix prevents most .env commits (via chokidar),
|
|
150
|
+
// but doesn't prevent `git add -u` from staging tracked .env files.
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
// ============================================================
|
|
154
|
+
// Bug fix verification: unicode filenames in git diff --cached
|
|
155
|
+
// ============================================================
|
|
156
|
+
describe('unicode filename handling in commitAndPush (BUG FIX)', () => {
|
|
157
|
+
it('git diff --cached with core.quotePath=false returns real filenames', () => {
|
|
158
|
+
const { local } = createTestRepo();
|
|
159
|
+
// Create and commit a unicode filename
|
|
160
|
+
const filename = 'caf\u00e9.txt';
|
|
161
|
+
commitFile(local, 'init.txt', 'hello', 'init');
|
|
162
|
+
// Stage a unicode file
|
|
163
|
+
writeFileSync(join(local, filename), 'content');
|
|
164
|
+
execFileSync('git', ['add', filename], { cwd: local });
|
|
165
|
+
// WITHOUT fix: git diff --cached --name-only returns octal-escaped
|
|
166
|
+
const withoutFix = execFileSync('git', ['diff', '--cached', '--name-only'], { cwd: local, encoding: 'utf-8' }).trim();
|
|
167
|
+
// WITH fix: git -c core.quotePath=false diff --cached --name-only returns real name
|
|
168
|
+
const withFix = execFileSync('git', ['-c', 'core.quotePath=false', 'diff', '--cached', '--name-only'], { cwd: local, encoding: 'utf-8' }).trim();
|
|
169
|
+
// The fixed version should contain the actual unicode character
|
|
170
|
+
expect(withFix).toContain('caf\u00e9.txt');
|
|
171
|
+
// The unfixed version may contain octal escaping (depends on git config)
|
|
172
|
+
// On most systems, git.quotePath defaults to true for non-ASCII
|
|
173
|
+
if (withoutFix.includes('\\')) {
|
|
174
|
+
// Confirms the bug existed: without the fix, git returns escaped names
|
|
175
|
+
expect(withoutFix).not.toContain('caf\u00e9');
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
it('staged file count is correct with unicode filenames', () => {
|
|
179
|
+
const { local } = createTestRepo();
|
|
180
|
+
commitFile(local, 'init.txt', 'hello', 'init');
|
|
181
|
+
// Stage multiple files including unicode names
|
|
182
|
+
const files = ['normal.txt', 'caf\u00e9.txt', '\u00fcber.ts', 'na\u00efve.md'];
|
|
183
|
+
for (const f of files) {
|
|
184
|
+
writeFileSync(join(local, f), `content of ${f}`);
|
|
185
|
+
execFileSync('git', ['add', f], { cwd: local });
|
|
186
|
+
}
|
|
187
|
+
const staged = execFileSync('git', ['-c', 'core.quotePath=false', 'diff', '--cached', '--name-only'], { cwd: local, encoding: 'utf-8' }).trim();
|
|
188
|
+
const stagedFiles = staged.split('\n').filter(Boolean);
|
|
189
|
+
expect(stagedFiles).toHaveLength(files.length);
|
|
190
|
+
for (const f of files) {
|
|
191
|
+
expect(stagedFiles).toContain(f);
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
// ============================================================
|
|
196
|
+
// Real-life scenario tests
|
|
197
|
+
// ============================================================
|
|
198
|
+
describe('real-life auto-commit scenarios', () => {
|
|
199
|
+
it('handles rapid file writes without losing changes', () => {
|
|
200
|
+
// Scenario: IDE save-all writes 10 files in quick succession.
|
|
201
|
+
// All should be captured for staging.
|
|
202
|
+
const { local } = createTestRepo();
|
|
203
|
+
commitFile(local, 'init.txt', 'hello', 'init');
|
|
204
|
+
// Rapidly create files (simulating what changedFiles set would collect)
|
|
205
|
+
const files = Array.from({ length: 10 }, (_, i) => `file-${i}.ts`);
|
|
206
|
+
for (const f of files) {
|
|
207
|
+
writeFileSync(join(local, f), `export const x${f.replace(/\W/g, '')} = true;`);
|
|
208
|
+
}
|
|
209
|
+
// Stage them all (simulating what commitAndPush does)
|
|
210
|
+
execFileSync('git', ['add', '--', ...files], { cwd: local, stdio: 'pipe' });
|
|
211
|
+
const staged = execFileSync('git', ['-c', 'core.quotePath=false', 'diff', '--cached', '--name-only'], { cwd: local, encoding: 'utf-8' }).trim().split('\n').filter(Boolean);
|
|
212
|
+
expect(staged).toHaveLength(10);
|
|
213
|
+
});
|
|
214
|
+
it('handles files deleted between detection and staging', () => {
|
|
215
|
+
// Scenario: chokidar fires for a temp file that gets deleted
|
|
216
|
+
// before git add runs. git add throws for non-existent files,
|
|
217
|
+
// but commitAndPush wraps it in try/catch so it's handled gracefully.
|
|
218
|
+
const { local } = createTestRepo();
|
|
219
|
+
commitFile(local, 'init.txt', 'hello', 'init');
|
|
220
|
+
const tempFile = join(local, 'temp.txt');
|
|
221
|
+
writeFileSync(tempFile, 'temporary');
|
|
222
|
+
// Delete before staging
|
|
223
|
+
rmSync(tempFile);
|
|
224
|
+
// git add -- temp.txt DOES throw for non-existent files
|
|
225
|
+
let threw = false;
|
|
226
|
+
try {
|
|
227
|
+
execFileSync('git', ['add', '--', 'temp.txt'], { cwd: local, stdio: 'pipe' });
|
|
228
|
+
}
|
|
229
|
+
catch {
|
|
230
|
+
threw = true;
|
|
231
|
+
}
|
|
232
|
+
// Confirmed: git add throws. commitAndPush catches this per batch.
|
|
233
|
+
expect(threw).toBe(true);
|
|
234
|
+
});
|
|
235
|
+
it('batch staging handles more than 50 files correctly', () => {
|
|
236
|
+
// commitAndPush batches git add into groups of 50.
|
|
237
|
+
// Verify nothing gets lost at batch boundaries.
|
|
238
|
+
const { local } = createTestRepo();
|
|
239
|
+
commitFile(local, 'init.txt', 'hello', 'init');
|
|
240
|
+
const fileCount = 120; // 50 + 50 + 20
|
|
241
|
+
const files = [];
|
|
242
|
+
for (let i = 0; i < fileCount; i++) {
|
|
243
|
+
const name = `batch-${String(i).padStart(3, '0')}.ts`;
|
|
244
|
+
writeFileSync(join(local, name), `export const x = ${i};`);
|
|
245
|
+
files.push(name);
|
|
246
|
+
}
|
|
247
|
+
// Simulate batch staging from commitAndPush
|
|
248
|
+
const BATCH_SIZE = 50;
|
|
249
|
+
for (let i = 0; i < files.length; i += BATCH_SIZE) {
|
|
250
|
+
const batch = files.slice(i, i + BATCH_SIZE);
|
|
251
|
+
execFileSync('git', ['add', '--', ...batch], { cwd: local, stdio: 'pipe' });
|
|
252
|
+
}
|
|
253
|
+
const staged = execFileSync('git', ['-c', 'core.quotePath=false', 'diff', '--cached', '--name-only'], { cwd: local, encoding: 'utf-8' }).trim().split('\n').filter(Boolean);
|
|
254
|
+
expect(staged).toHaveLength(fileCount);
|
|
255
|
+
});
|
|
256
|
+
it('commit message includes ISO timestamp', () => {
|
|
257
|
+
const { local } = createTestRepo();
|
|
258
|
+
commitFile(local, 'init.txt', 'hello', 'init');
|
|
259
|
+
writeFileSync(join(local, 'new.ts'), 'export {}');
|
|
260
|
+
execFileSync('git', ['add', 'new.ts'], { cwd: local, stdio: 'pipe' });
|
|
261
|
+
const timestamp = new Date().toISOString().replace('T', ' ').slice(0, 19);
|
|
262
|
+
execFileSync('git', ['commit', '-m', `dev: updated ${timestamp}`], { cwd: local, stdio: 'pipe' });
|
|
263
|
+
const log = execFileSync('git', ['log', '-1', '--format=%s'], {
|
|
264
|
+
cwd: local, encoding: 'utf-8',
|
|
265
|
+
}).trim();
|
|
266
|
+
expect(log).toMatch(/^dev: updated \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
|
|
267
|
+
});
|
|
268
|
+
it('pull --rebase then push works after remote has new commits', () => {
|
|
269
|
+
const { local, remote } = createTestRepo();
|
|
270
|
+
commitFile(local, 'init.txt', 'hello', 'init');
|
|
271
|
+
execFileSync('git', ['push', 'runwork', 'main'], { cwd: local, stdio: 'pipe' });
|
|
272
|
+
// Simulate remote commit (e.g. DO onStart creating files)
|
|
273
|
+
const secondary = makeTempDir('secondary');
|
|
274
|
+
execFileSync('git', ['clone', remote, secondary]);
|
|
275
|
+
execFileSync('git', ['config', 'user.email', 'server@test.com'], { cwd: secondary });
|
|
276
|
+
execFileSync('git', ['config', 'user.name', 'Server'], { cwd: secondary });
|
|
277
|
+
commitFile(secondary, 'server-file.txt', 'from server', 'server: init');
|
|
278
|
+
execFileSync('git', ['push', 'origin', 'main'], { cwd: secondary, stdio: 'pipe' });
|
|
279
|
+
// Local commit (user edit)
|
|
280
|
+
commitFile(local, 'user-file.ts', 'export {}', 'dev: user edit');
|
|
281
|
+
// Simulate commitAndPush: pull --rebase then push
|
|
282
|
+
execFileSync('git', ['pull', '--rebase', 'runwork', 'main'], { cwd: local, stdio: 'pipe' });
|
|
283
|
+
execFileSync('git', ['push', 'runwork', 'main'], { cwd: local, stdio: 'pipe' });
|
|
284
|
+
// Both files should exist
|
|
285
|
+
expect(existsSync(join(local, 'server-file.txt'))).toBe(true);
|
|
286
|
+
expect(existsSync(join(local, 'user-file.ts'))).toBe(true);
|
|
287
|
+
});
|
|
288
|
+
it('merge with --allow-unrelated-histories combines diverged trees', () => {
|
|
289
|
+
// Scenario: template update on web UI rewrites history.
|
|
290
|
+
// The merge fallback (used when rebase fails) should combine both trees.
|
|
291
|
+
const { local, remote } = createTestRepo();
|
|
292
|
+
commitFile(local, 'local-file.txt', 'local content', 'local init');
|
|
293
|
+
// Create a completely separate history on the remote
|
|
294
|
+
const other = makeTempDir('template-update');
|
|
295
|
+
execFileSync('git', ['init', other]);
|
|
296
|
+
execFileSync('git', ['config', 'user.email', 'server@test.com'], { cwd: other });
|
|
297
|
+
execFileSync('git', ['config', 'user.name', 'Server'], { cwd: other });
|
|
298
|
+
commitFile(other, 'template-file.txt', 'new template', 'template: v2');
|
|
299
|
+
execFileSync('git', ['remote', 'add', 'origin', remote], { cwd: other });
|
|
300
|
+
execFileSync('git', ['push', 'origin', 'main'], { cwd: other, stdio: 'pipe' });
|
|
301
|
+
// Fetch remote
|
|
302
|
+
execFileSync('git', ['fetch', 'runwork', 'main'], { cwd: local, stdio: 'pipe' });
|
|
303
|
+
// Merge with unrelated histories
|
|
304
|
+
execFileSync('git', ['merge', 'runwork/main', '--allow-unrelated-histories', '--no-edit'], { cwd: local, stdio: 'pipe' });
|
|
305
|
+
// Both files should exist after merge
|
|
306
|
+
expect(existsSync(join(local, 'local-file.txt'))).toBe(true);
|
|
307
|
+
expect(existsSync(join(local, 'template-file.txt'))).toBe(true);
|
|
308
|
+
});
|
|
309
|
+
it('binary files are excluded from fast sync but included in git', () => {
|
|
310
|
+
// Scenario: user adds an image file. Fast sync should skip it,
|
|
311
|
+
// but git should still commit and push it.
|
|
312
|
+
const { local } = createTestRepo();
|
|
313
|
+
commitFile(local, 'init.txt', 'hello', 'init');
|
|
314
|
+
const binaryExtensions = ['.png', '.jpg', '.woff2', '.pdf', '.wasm'];
|
|
315
|
+
for (const ext of binaryExtensions) {
|
|
316
|
+
writeFileSync(join(local, `file${ext}`), Buffer.from([0x00, 0xFF, 0x89, 0x50]));
|
|
317
|
+
}
|
|
318
|
+
// All binary files should be stageable by git
|
|
319
|
+
execFileSync('git', ['add', '.'], { cwd: local, stdio: 'pipe' });
|
|
320
|
+
const staged = execFileSync('git', ['-c', 'core.quotePath=false', 'diff', '--cached', '--name-only'], { cwd: local, encoding: 'utf-8' }).trim().split('\n').filter(Boolean);
|
|
321
|
+
for (const ext of binaryExtensions) {
|
|
322
|
+
expect(staged).toContain(`file${ext}`);
|
|
323
|
+
}
|
|
324
|
+
});
|
|
325
|
+
it('handles .gitignore interaction: ignored files not staged by git add -u', () => {
|
|
326
|
+
// Scenario: user has .gitignore. Modified ignored files should NOT
|
|
327
|
+
// be staged by git add -u.
|
|
328
|
+
const { local } = createTestRepo();
|
|
329
|
+
writeFileSync(join(local, '.gitignore'), 'dist/\n*.tmp\n');
|
|
330
|
+
commitFile(local, '.gitignore', readFileSync(join(local, '.gitignore'), 'utf-8'), 'add gitignore');
|
|
331
|
+
commitFile(local, 'src/app.ts', 'export {}', 'init');
|
|
332
|
+
// Create ignored files
|
|
333
|
+
mkdirSync(join(local, 'dist'));
|
|
334
|
+
writeFileSync(join(local, 'dist', 'bundle.js'), 'compiled');
|
|
335
|
+
writeFileSync(join(local, 'temp.tmp'), 'temporary');
|
|
336
|
+
// git add -u should NOT stage ignored files
|
|
337
|
+
execFileSync('git', ['add', '-u'], { cwd: local, stdio: 'pipe' });
|
|
338
|
+
const staged = execFileSync('git', ['diff', '--cached', '--name-only'], { cwd: local, encoding: 'utf-8' }).trim();
|
|
339
|
+
// Nothing should be staged (only gitignored files were modified)
|
|
340
|
+
expect(staged).toBe('');
|
|
341
|
+
});
|
|
342
|
+
it('handles empty working directory after initial commit', () => {
|
|
343
|
+
// Edge case: all files deleted, nothing to stage
|
|
344
|
+
const { local } = createTestRepo();
|
|
345
|
+
commitFile(local, 'init.txt', 'hello', 'init');
|
|
346
|
+
execFileSync('git', ['rm', 'init.txt'], { cwd: local, stdio: 'pipe' });
|
|
347
|
+
execFileSync('git', ['commit', '-m', 'delete all'], { cwd: local, stdio: 'pipe' });
|
|
348
|
+
// git add -u with nothing to add
|
|
349
|
+
execFileSync('git', ['add', '-u'], { cwd: local, stdio: 'pipe' });
|
|
350
|
+
const staged = execFileSync('git', ['diff', '--cached', '--name-only'], { cwd: local, encoding: 'utf-8' }).trim();
|
|
351
|
+
expect(staged).toBe('');
|
|
352
|
+
});
|
|
353
|
+
it('push -u sets upstream on first push', () => {
|
|
354
|
+
// commitAndPush tries `git rev-parse --abbrev-ref @{u}` to check
|
|
355
|
+
// for upstream. If it fails, it uses `push -u` to set upstream.
|
|
356
|
+
const { local, remote } = createTestRepo();
|
|
357
|
+
commitFile(local, 'init.txt', 'hello', 'init');
|
|
358
|
+
// No upstream configured yet
|
|
359
|
+
let hasUpstream = true;
|
|
360
|
+
try {
|
|
361
|
+
execFileSync('git', ['rev-parse', '--abbrev-ref', '@{u}'], { cwd: local, stdio: 'pipe' });
|
|
362
|
+
}
|
|
363
|
+
catch {
|
|
364
|
+
hasUpstream = false;
|
|
365
|
+
}
|
|
366
|
+
expect(hasUpstream).toBe(false);
|
|
367
|
+
// Push with -u to set upstream
|
|
368
|
+
execFileSync('git', ['push', '-u', 'runwork', 'main'], { cwd: local, stdio: 'pipe' });
|
|
369
|
+
// Now upstream should be set
|
|
370
|
+
const upstream = execFileSync('git', ['rev-parse', '--abbrev-ref', '@{u}'], { cwd: local, encoding: 'utf-8' }).trim();
|
|
371
|
+
expect(upstream).toBe('runwork/main');
|
|
372
|
+
});
|
|
373
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|