@pixelbyte-software/pixcode 1.47.1 → 1.47.2

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.
@@ -0,0 +1,141 @@
1
+ import assert from 'node:assert/strict';
2
+ import { spawnSync } from 'node:child_process';
3
+ import fs from 'node:fs';
4
+ import os from 'node:os';
5
+ import path from 'node:path';
6
+
7
+ const serverIndex = fs.readFileSync('server/index.js', 'utf8');
8
+ const modal = fs.readFileSync('src/components/version-upgrade/view/VersionUpgradeModal.tsx', 'utf8');
9
+ const updater = fs.readFileSync('scripts/update-git-install.mjs', 'utf8');
10
+ const updaterPath = path.resolve('scripts/update-git-install.mjs');
11
+
12
+ assert.match(
13
+ serverIndex,
14
+ /update-git-install\.mjs/,
15
+ 'Git install updates should use the safe updater script instead of raw git pull.',
16
+ );
17
+
18
+ assert.doesNotMatch(
19
+ serverIndex,
20
+ /git checkout main && git pull && npm install/,
21
+ 'Server update command should not use the brittle raw git checkout/pull/install chain.',
22
+ );
23
+
24
+ assert.match(
25
+ modal,
26
+ /node scripts\/update-git-install\.mjs/,
27
+ 'Version modal should show the safe git updater command.',
28
+ );
29
+
30
+ assert.match(
31
+ updater,
32
+ /stash[\s\S]*push[\s\S]*--include-untracked[\s\S]*--message/,
33
+ 'Safe updater should stash dirty tracked and untracked files before updating.',
34
+ );
35
+
36
+ assert.match(
37
+ updater,
38
+ /branch[\s\S]*backupBranch/,
39
+ 'Safe updater should preserve divergent local commits in a backup branch.',
40
+ );
41
+
42
+ assert.match(
43
+ updater,
44
+ /reset[\s\S]*--hard[\s\S]*origin\/main/,
45
+ 'Safe updater should be able to normalize a divergent install checkout after preserving it.',
46
+ );
47
+
48
+ assert.match(
49
+ updater,
50
+ /npm[\s\S]*install[\s\S]*--no-audit[\s\S]*--no-fund/,
51
+ 'Safe updater should reinstall dependencies after updating source files.',
52
+ );
53
+
54
+ const tempRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'pixcode-git-update-'));
55
+ const origin = path.join(tempRoot, 'origin.git');
56
+ const source = path.join(tempRoot, 'source');
57
+ const install = path.join(tempRoot, 'install');
58
+
59
+ function run(command, args, cwd) {
60
+ const result = spawnSync(command, args, {
61
+ cwd,
62
+ encoding: 'utf8',
63
+ env: {
64
+ ...process.env,
65
+ GIT_AUTHOR_NAME: 'Pixcode Smoke',
66
+ GIT_AUTHOR_EMAIL: 'smoke@pixcode.local',
67
+ GIT_COMMITTER_NAME: 'Pixcode Smoke',
68
+ GIT_COMMITTER_EMAIL: 'smoke@pixcode.local',
69
+ },
70
+ });
71
+
72
+ assert.equal(
73
+ result.status,
74
+ 0,
75
+ `${command} ${args.join(' ')} failed\nstdout:\n${result.stdout}\nstderr:\n${result.stderr}`,
76
+ );
77
+
78
+ return result.stdout.trim();
79
+ }
80
+
81
+ function writePackage(version) {
82
+ fs.writeFileSync(
83
+ path.join(source, 'package.json'),
84
+ JSON.stringify({ name: 'pixcode-update-smoke', version }, null, 2),
85
+ );
86
+ fs.writeFileSync(
87
+ path.join(source, 'package-lock.json'),
88
+ JSON.stringify({
89
+ name: 'pixcode-update-smoke',
90
+ version,
91
+ lockfileVersion: 3,
92
+ requires: true,
93
+ packages: {
94
+ '': {
95
+ name: 'pixcode-update-smoke',
96
+ version,
97
+ },
98
+ },
99
+ }, null, 2),
100
+ );
101
+ }
102
+
103
+ fs.mkdirSync(source, { recursive: true });
104
+ run('git', ['init', '--bare', origin], tempRoot);
105
+ run('git', ['init', '-b', 'main'], source);
106
+ writePackage('1.0.0');
107
+ fs.writeFileSync(path.join(source, 'tracked.txt'), 'old\n');
108
+ run('git', ['add', '.'], source);
109
+ run('git', ['commit', '-m', 'initial'], source);
110
+ run('git', ['remote', 'add', 'origin', origin], source);
111
+ run('git', ['push', '-u', 'origin', 'main'], source);
112
+ run('git', ['symbolic-ref', 'HEAD', 'refs/heads/main'], origin);
113
+ run('git', ['clone', origin, install], tempRoot);
114
+
115
+ writePackage('1.0.1');
116
+ fs.writeFileSync(path.join(source, 'tracked.txt'), 'new\n');
117
+ run('git', ['add', '.'], source);
118
+ run('git', ['commit', '-m', 'update'], source);
119
+ run('git', ['push', 'origin', 'main'], source);
120
+
121
+ fs.writeFileSync(path.join(install, 'tracked.txt'), 'local dirty change\n');
122
+ fs.writeFileSync(path.join(install, 'untracked.txt'), 'local untracked change\n');
123
+ run(process.execPath, [updaterPath], install);
124
+
125
+ assert.equal(
126
+ JSON.parse(fs.readFileSync(path.join(install, 'package.json'), 'utf8')).version,
127
+ '1.0.1',
128
+ 'Safe updater should fast-forward the install checkout.',
129
+ );
130
+ assert.equal(
131
+ fs.readFileSync(path.join(install, 'tracked.txt'), 'utf8'),
132
+ 'new\n',
133
+ 'Safe updater should apply the remote tracked file after stashing local edits.',
134
+ );
135
+ assert.match(
136
+ run('git', ['stash', 'list'], install),
137
+ /pixcode-auto-update-/,
138
+ 'Safe updater should leave local dirty files recoverable in git stash.',
139
+ );
140
+
141
+ console.log('git install update smoke passed');
@@ -80,6 +80,12 @@ assert.match(
80
80
  'Workbench should request compact composer behavior in the right CLI pane.',
81
81
  );
82
82
 
83
+ assert.match(
84
+ workbench,
85
+ /activeTab === 'chat' && activityPanel === 'projects'/,
86
+ 'Projects activity should stay selected while the center chat tab is active.',
87
+ );
88
+
83
89
  assert.match(chatInterface, /compactComposer\?: boolean/, 'ChatInterface should expose compactComposer for narrow workbench panes.');
84
90
  assert.match(chatComposer, /compact\?: boolean/, 'ChatComposer should expose a compact prop.');
85
91
  assert.match(chatComposer, /flex-wrap/, 'ChatComposer footer should wrap controls in narrow panes.');
@@ -0,0 +1,128 @@
1
+ #!/usr/bin/env node
2
+ import { spawn } from 'node:child_process';
3
+ import fs from 'node:fs';
4
+ import path from 'node:path';
5
+
6
+ const repoRoot = process.cwd();
7
+ const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
8
+ const stashMessage = `pixcode-auto-update-${timestamp}`;
9
+ const backupBranch = `pixcode-backup-before-update-${timestamp}`;
10
+
11
+ function log(message) {
12
+ process.stdout.write(`${message}\n`);
13
+ }
14
+
15
+ function run(command, args, options = {}) {
16
+ const {
17
+ allowFailure = false,
18
+ collectOutput = false,
19
+ env = process.env,
20
+ } = options;
21
+
22
+ return new Promise((resolve, reject) => {
23
+ log(`$ ${[command, ...args].join(' ')}`);
24
+ const child = spawn(command, args, {
25
+ cwd: repoRoot,
26
+ env,
27
+ shell: false,
28
+ stdio: ['ignore', 'pipe', 'pipe'],
29
+ });
30
+
31
+ let stdout = '';
32
+ let stderr = '';
33
+
34
+ child.stdout?.on('data', (chunk) => {
35
+ const text = chunk.toString();
36
+ stdout += text;
37
+ process.stdout.write(text);
38
+ });
39
+
40
+ child.stderr?.on('data', (chunk) => {
41
+ const text = chunk.toString();
42
+ stderr += text;
43
+ process.stderr.write(text);
44
+ });
45
+
46
+ child.on('error', reject);
47
+ child.on('close', (code) => {
48
+ const result = { code, stdout, stderr };
49
+ if (code === 0 || allowFailure) {
50
+ resolve(collectOutput ? result : code);
51
+ return;
52
+ }
53
+
54
+ const error = new Error(`${command} ${args.join(' ')} exited with code ${code}`);
55
+ error.result = result;
56
+ reject(error);
57
+ });
58
+ });
59
+ }
60
+
61
+ async function getOutput(command, args, options = {}) {
62
+ const result = await run(command, args, { ...options, collectOutput: true });
63
+ return result.stdout.trim();
64
+ }
65
+
66
+ async function main() {
67
+ if (!fs.existsSync(path.join(repoRoot, '.git'))) {
68
+ throw new Error(`Git metadata not found in ${repoRoot}`);
69
+ }
70
+
71
+ log('Pixcode safe git update started.');
72
+ log(`Repository: ${repoRoot}`);
73
+
74
+ await run('git', ['rev-parse', '--is-inside-work-tree']);
75
+ await run('git', ['fetch', 'origin', 'main']);
76
+
77
+ const status = await getOutput('git', ['status', '--porcelain', '--untracked-files=all']);
78
+ if (status) {
79
+ log('Local checkout has modified or untracked files.');
80
+ log(`Saving them to git stash: ${stashMessage}`);
81
+ await run('git', [
82
+ '-c',
83
+ 'user.name=Pixcode Updater',
84
+ '-c',
85
+ 'user.email=updater@pixcode.local',
86
+ 'stash',
87
+ 'push',
88
+ '--include-untracked',
89
+ '--message',
90
+ stashMessage,
91
+ ]);
92
+ log('Local changes are preserved in git stash.');
93
+ } else {
94
+ log('Working tree is clean.');
95
+ }
96
+
97
+ const checkoutMain = await run('git', ['checkout', 'main'], { allowFailure: true, collectOutput: true });
98
+ if (checkoutMain.code !== 0) {
99
+ log('Local main branch checkout failed; recreating main from origin/main.');
100
+ await run('git', ['checkout', '-B', 'main', 'origin/main']);
101
+ }
102
+
103
+ const isAncestor = await run('git', ['merge-base', '--is-ancestor', 'HEAD', 'origin/main'], {
104
+ allowFailure: true,
105
+ collectOutput: true,
106
+ });
107
+
108
+ if (isAncestor.code === 0) {
109
+ await run('git', ['merge', '--ff-only', 'origin/main']);
110
+ } else if (isAncestor.code === 1) {
111
+ log(`Local main has commits that are not on origin/main. Preserving them in branch: ${backupBranch}`);
112
+ await run('git', ['branch', backupBranch]);
113
+ await run('git', ['reset', '--hard', 'origin/main']);
114
+ } else {
115
+ throw new Error('Could not compare local main with origin/main.');
116
+ }
117
+
118
+ const packageVersion = JSON.parse(fs.readFileSync(path.join(repoRoot, 'package.json'), 'utf8')).version;
119
+ log(`Repository updated to Pixcode ${packageVersion}.`);
120
+
121
+ await run('npm', ['install', '--no-audit', '--no-fund']);
122
+ log('Pixcode git install update completed.');
123
+ }
124
+
125
+ main().catch((error) => {
126
+ process.stderr.write(`Pixcode git install update failed: ${error.message}\n`);
127
+ process.exit(1);
128
+ });
package/server/index.js CHANGED
@@ -482,18 +482,21 @@ app.use(express.static(path.join(APP_ROOT, 'public'), {
482
482
  // npm tarball, extracts it to the writable runtime dir, and triggers
483
483
  // a server restart so the Electron wrapper respawns with new code.
484
484
  // ~4 MB download, ~10 s; no npm/git/shell required on the host.
485
- // 2. installMode === 'git' → `git pull && npm install` in-place.
485
+ // 2. installMode === 'git' → safe git updater script. It stashes dirty
486
+ // checkout state before pulling so source installs do not fail on local
487
+ // modified files left by older releases or manual edits.
486
488
  // 3. fallback → `npm install -g …` (classic npm-distributed install).
487
489
  app.post('/api/system/update', authenticateToken, async (req, res) => {
488
490
  const projectRoot = APP_ROOT;
489
491
  console.log('Starting system update from directory:', projectRoot);
490
492
 
491
493
  const runtimeDir = process.env.PIXCODE_RUNTIME_DIR || null;
494
+ const gitUpdateScript = path.join(projectRoot, 'scripts', 'update-git-install.mjs');
492
495
 
493
496
  const updateCommand = IS_PLATFORM
494
497
  ? 'npm run update:platform'
495
498
  : installMode === 'git'
496
- ? 'git checkout main && git pull && npm install'
499
+ ? `${JSON.stringify(process.execPath)} ${JSON.stringify(gitUpdateScript)}`
497
500
  : 'npm install -g @pixelbyte-software/pixcode@latest';
498
501
 
499
502
  const updateCwd = IS_PLATFORM || installMode === 'git'
@@ -738,8 +741,9 @@ app.post('/api/system/update', authenticateToken, async (req, res) => {
738
741
  // Short-circuit for "already on latest" in the npm-global path so
739
742
  // users don't accidentally crash their own daemon by clicking Update
740
743
  // while already up to date. The runtime-dir branch above already has
741
- // this guard (line ~504); replicate it for npm mode. Git mode skips
742
- // this since `git pull` is harmless when already up to date.
744
+ // this guard (line ~504); replicate it for npm mode. Git mode still
745
+ // runs because users may be on the latest package version but behind
746
+ // the source branch or have a dirty checkout that needs normalization.
743
747
  if (!IS_PLATFORM && installMode === 'npm') {
744
748
  try {
745
749
  send('log', { stream: 'meta', chunk: 'Querying registry for latest version…\n' });