Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

fix: Desktop profile picture upload (the daemon passes /avatars on to the backend) (#1921)

0xken1539d454d60795
diff --git a/cli/src/hookServer.spec.ts b/cli/src/hookServer.spec.ts
index 3afde9cff..3c81ef9c1 100644
--- a/cli/src/hookServer.spec.ts
+++ b/cli/src/hookServer.spec.ts
@@ -477,6 +477,25 @@ describe('Super Tab attachment pass-through', () => {
expect(await person.json()).toEqual({ path: '/api/super-tabs/tab-1/attachments', bytes: 1 })
})
+ // A profile picture goes the same way (Desktop's Upload picture…); before this, the daemon answered 404 and Desktop
+ // showed only "Could not upload the file".
+ it('hands an avatar picture to the pass-through, guarded the same way', async () => {
+ const forward = vi.fn(async (req: import('node:http').IncomingMessage, res: import('node:http').ServerResponse, path: string) => {
+ let bytes = 0
+ for await (const chunk of req) bytes += (chunk as Buffer).byteLength
+ res.writeHead(200, { 'Content-Type': 'application/json' })
+ res.end(JSON.stringify({ path, bytes }))
+ })
+ const { base } = await start({ onSuperTabAttachment: forward })
+ const headers = { 'x-adapter-local': '1', 'content-type': 'multipart/form-data; boundary=x' }
+ expect((await fetch(`${base}/api/super-tabs/tab-1/avatars`, { method: 'POST',
+ headers: { ...headers, origin: 'https://untrusted.example' }, body: 'x' })).status).toBe(403)
+ expect(forward).not.toHaveBeenCalled()
+ const r = await fetch(`${base}/api/super-tabs/tab-1/avatars`, { method: 'POST', headers, body: 'picture' })
+ expect(r.status).toBe(200)
+ expect(await r.json()).toEqual({ path: '/api/super-tabs/tab-1/avatars', bytes: 7 })
+ })
+
it('is unavailable on a daemon without it', async () => {
const { base } = await start({})
expect((await fetch(`${base}/api/super-tabs/tab-1/attachments`, { method: 'POST',
diff --git a/cli/src/hookServer.ts b/cli/src/hookServer.ts
index 276155e90..3328a6c87 100644
--- a/cli/src/hookServer.ts
+++ b/cli/src/hookServer.ts
@@ -1105,7 +1105,9 @@ export function startHookServer(
} catch { json(502, { success: false, error: { code: 'USAGE_UNAVAILABLE', message: 'Product usage unavailable' } }) }
return
}
- const attachment = req.method === 'POST' ? /^\/api\/super-tabs\/[A-Za-z0-9_-]{1,160}\/attachments$/.exec(url) : null
+ // A profile picture (`/avatars`) too: without it the daemon answered 404 and Desktop's Upload picture… failed
+ // with only "Could not upload the file".
+ const attachment = req.method === 'POST' ? /^\/api\/super-tabs\/[A-Za-z0-9_-]{1,160}\/(attachments|avatars)$/.exec(url) : null
if (attachment) {
if (!localOk) { json(403, { error: 'FORBIDDEN' }); return }
if (!handlers.onSuperTabAttachment) { json(503, { error: 'UNAVAILABLE' }); return }
diff --git a/desktop/lib/super_tabs/avatar_upload.dart b/desktop/lib/super_tabs/avatar_upload.dart
index 66084c54c..5ea037479 100644
--- a/desktop/lib/super_tabs/avatar_upload.dart
+++ b/desktop/lib/super_tabs/avatar_upload.dart
@@ -51,6 +51,16 @@ SuperTabAvatarUpload uploadAvatarWith(ApiClient Function() api) =>
body['success'] == true) {
return Map<String, dynamic>.from(body['data'] as Map);
}
+ // The daemon's own 404, a bare code: a CLI too old to pass pictures on
+ // (Desktop 1.3.30 read it as "Could not upload the file", and retrying
+ // never helps). The backend's refusals carry `{code, message}`.
+ if (response.statusCode == 404 && body is Map && body['error'] is! Map) {
+ throw const SuperTabFailure(
+ 'UPDATE_HARNESS',
+ 'Update Harness on this computer to upload pictures.',
+ statusCode: 404,
+ );
+ }
throw superTabUploadRefusal(response);
};
diff --git a/desktop/test/super_tab_upload_test.dart b/desktop/test/super_tab_upload_test.dart
index 09716fc40..6770eba31 100644
--- a/desktop/test/super_tab_upload_test.dart
+++ b/desktop/test/super_tab_upload_test.dart
@@ -12,6 +12,7 @@ import 'package:harness/api/access_token_source.dart';
import 'package:harness/auth/auth_session.dart';
import 'package:harness/core/config.dart';
import 'package:harness/super_tabs/attachment_upload.dart';
+import 'package:harness/super_tabs/avatar_upload.dart';
import 'package:harness/super_tabs/controller.dart';
void main() {
@@ -179,6 +180,93 @@ void main() {
expect(seen.single.local, '1');
});
+ group('a profile picture', () {
+ late SuperTabAvatarUpload avatar;
+
+ setUp(() {
+ avatar = uploadAvatarWith(
+ () => ApiClient(
+ config: AppConfig(
+ apiBaseUrl: 'http://unused.invalid',
+ localCliBaseUrl: 'http://127.0.0.1:${server.port}',
+ ),
+ session: AuthSession(),
+ ),
+ );
+ });
+
+ Future<Map<String, dynamic>> sendPicture() =>
+ avatar(tabId: 'tab 1', png: Uint8List.fromList(List.filled(500, 7)));
+
+ test('goes through the daemon as a one-file form', () async {
+ reply = (
+ 200,
+ {
+ 'success': true,
+ 'data': {
+ 'avatar': {'id': 'p1', 'url': 'https://signed.example/p1'},
+ },
+ },
+ );
+
+ final answer = await sendPicture();
+
+ expect((answer['avatar'] as Map)['id'], 'p1');
+ final request = seen.single;
+ expect(request.path, '/api/super-tabs/tab%201/avatars');
+ expect(request.local, '1');
+ expect(request.type, 'multipart/form-data');
+ expect(request.body, contains('filename="avatar.png"'));
+ });
+
+ // Desktop 1.3.30 on a CLI that did not pass /avatars on: the daemon's
+ // own 404 read only "Could not upload the file. Try again.", which no
+ // retry fixes.
+ test('a daemon without the route says to update Harness', () async {
+ reply = (404, {'error': 'not found'});
+
+ await expectLater(
+ sendPicture(),
+ throwsA(
+ isA<SuperTabFailure>()
+ .having((f) => f.code, 'code', 'UPDATE_HARNESS')
+ .having(
+ (f) => f.message,
+ 'message',
+ 'Update Harness on this computer to upload pictures.',
+ )
+ .having((f) => f.statusCode, 'status', 404),
+ ),
+ );
+ });
+
+ test('a backend refusal keeps its own words', () async {
+ reply = (
+ 503,
+ {
+ 'success': false,
+ 'error': {
+ 'code': 'AVATARS_UNAVAILABLE',
+ 'message': 'Uploading pictures is not set up on this server yet.',
+ },
+ },
+ );
+
+ await expectLater(
+ sendPicture(),
+ throwsA(
+ isA<SuperTabFailure>()
+ .having((f) => f.code, 'code', 'AVATARS_UNAVAILABLE')
+ .having(
+ (f) => f.message,
+ 'message',
+ 'Uploading pictures is not set up on this server yet.',
+ ),
+ ),
+ );
+ });
+ });
+
group('from a browser, straight to the backend', () {
late AccessTokenSource tokens;
final refreshes = <bool>[];