fix(server): percent-encode non-ASCII directory headers to OpenCode
This commit is contained in:
@@ -200,7 +200,9 @@ const fetchMessage = async ({ sessionId, messageId, directory, buildOpenCodeUrl,
|
||||
const response = await fetch(url, {
|
||||
headers: {
|
||||
accept: 'application/json',
|
||||
'x-opencode-directory': directory,
|
||||
// Percent-encoded to match the SDK wire format; raw non-ASCII values
|
||||
// are rejected by OpenCode.
|
||||
'x-opencode-directory': encodeURIComponent(directory),
|
||||
...getOpenCodeAuthHeaders(),
|
||||
},
|
||||
signal: AbortSignal.timeout(10_000),
|
||||
|
||||
@@ -74,6 +74,20 @@ const prepare = (app, directory, sources) => request(app)
|
||||
.expect(200);
|
||||
|
||||
describe('session image assets', () => {
|
||||
it('percent-encodes the directory header on the message fetch', async () => {
|
||||
const fixture = await createFixture();
|
||||
await prepare(fixture.app, fixture.directory, ['image.png']);
|
||||
|
||||
expect(fixture.fetchMock).toHaveBeenCalledWith(
|
||||
expect.any(URL),
|
||||
expect.objectContaining({
|
||||
headers: expect.objectContaining({
|
||||
'x-opencode-directory': encodeURIComponent(fixture.directory),
|
||||
}),
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it('prepares workspace and OpenCode temporary images with one message fetch', async () => {
|
||||
const fixture = await createFixture({ sources: ['workspace.png'] });
|
||||
await fs.writeFile(path.join(fixture.directory, 'workspace.png'), PNG);
|
||||
|
||||
Reference in New Issue
Block a user