Skip to content

Commit 4536dfe

Browse files
author
deepshekhardas
committed
fix: useRealtimeStream returns json-string instead of object for v2 streams (#3169)
1 parent 88f1eda commit 4536dfe

4 files changed

Lines changed: 80 additions & 51 deletions

File tree

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
FROM golang
22

3-
43
RUN go install github.com/pressly/goose/v3/cmd/goose@latest
54

6-
5+
WORKDIR /app
76
COPY ./schema ./schema
7+
COPY ./cmd ./cmd
8+
COPY ./migrate.sh ./migrate.sh
9+
10+
RUN go build -o /usr/local/bin/transform ./cmd/transform/main.go
11+
RUN chmod +x ./migrate.sh
812

913
ENV GOOSE_DRIVER=clickhouse
1014
ENV GOOSE_DBSTRING="tcp://default:password@clickhouse:9000"
1115
ENV GOOSE_MIGRATION_DIR=./schema
12-
CMD ["goose", "up"]
16+
17+
ENTRYPOINT ["./migrate.sh"]
18+
CMD ["up"]

packages/build/src/extensions/playwright.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -317,22 +317,26 @@ class PlaywrightExtension implements BuildExtension {
317317

318318
Array.from(browsersToInstall).forEach((browser) => {
319319
instructions.push(
320-
`RUN grep -A5 -m1 "browser: ${browser}" /tmp/browser-info.txt > /tmp/${browser}-info.txt`,
320+
// Extract the block for the specific browser.
321+
// We look for a line starting with "browser: {browser}" OR "{browser} v" (legacy)
322+
// Then we collect lines until the next block starts (line starting with browser: or certain chars) or an empty line.
323+
`RUN awk '/^browser: ${browser}|^${browser} v/{flag=1; print; next} /^(browser:|[a-z-]+ v)/{flag=0} flag' /tmp/browser-info.txt > /tmp/${browser}-info.txt`,
321324

322-
`RUN INSTALL_DIR=$(grep "Install location:" /tmp/${browser}-info.txt | cut -d':' -f2- | xargs) && \
325+
`RUN INSTALL_DIR=$(grep -i "Install location:" /tmp/${browser}-info.txt | cut -d':' -f2- | xargs) && \
323326
DIR_NAME=$(basename "$INSTALL_DIR") && \
324-
if [ -z "$DIR_NAME" ]; then echo "Failed to extract installation directory for ${browser}"; exit 1; fi && \
327+
if [ -z "$DIR_NAME" ]; then echo "Failed to extract installation directory for ${browser}. Content of /tmp/${browser}-info.txt:"; cat /tmp/${browser}-info.txt; exit 1; fi && \
325328
MS_DIR="/ms-playwright/$DIR_NAME" && \
326329
mkdir -p "$MS_DIR"`,
327330

328-
`RUN DOWNLOAD_URL=$(grep "Download url:" /tmp/${browser}-info.txt | cut -d':' -f2- | xargs | sed "s/mac-arm64/linux/g" | sed "s/mac-15-arm64/ubuntu-20.04/g") && \
331+
`RUN DOWNLOAD_URL=$(grep -i "Download url:" /tmp/${browser}-info.txt | cut -d':' -f2- | xargs | sed "s/mac-arm64/linux/g" | sed "s/mac-15-arm64/ubuntu-20.04/g") && \
329332
if [ -z "$DOWNLOAD_URL" ]; then echo "Failed to extract download URL for ${browser}"; exit 1; fi && \
330333
echo "Downloading ${browser} from $DOWNLOAD_URL" && \
331334
curl -L -o /tmp/${browser}.zip "$DOWNLOAD_URL" && \
332335
if [ $? -ne 0 ]; then echo "Failed to download ${browser}"; exit 1; fi && \
333-
unzip -q /tmp/${browser}.zip -d "/ms-playwright/$(basename $(grep "Install location:" /tmp/${browser}-info.txt | cut -d':' -f2- | xargs))" && \
336+
INSTALL_LOCATION=$(grep -i "Install location:" /tmp/${browser}-info.txt | cut -d':' -f2- | xargs) && \
337+
unzip -q /tmp/${browser}.zip -d "/ms-playwright/$(basename "$INSTALL_LOCATION")" && \
334338
if [ $? -ne 0 ]; then echo "Failed to extract ${browser}"; exit 1; fi && \
335-
chmod -R +x "/ms-playwright/$(basename $(grep "Install location:" /tmp/${browser}-info.txt | cut -d':' -f2- | xargs))" && \
339+
chmod -R +x "/ms-playwright/$(basename "$INSTALL_LOCATION")" && \
336340
rm /tmp/${browser}.zip`
337341
);
338342
});

packages/core/src/v3/apiClient/runStream.ts

Lines changed: 42 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -20,36 +20,36 @@ import { zodShapeStream } from "./stream.js";
2020

2121
export type RunShape<TRunTypes extends AnyRunTypes> = TRunTypes extends AnyRunTypes
2222
? {
23-
id: string;
24-
taskIdentifier: TRunTypes["taskIdentifier"];
25-
payload: TRunTypes["payload"];
26-
output?: TRunTypes["output"];
27-
createdAt: Date;
28-
updatedAt: Date;
29-
status: RunStatus;
30-
durationMs: number;
31-
costInCents: number;
32-
baseCostInCents: number;
33-
tags: string[];
34-
idempotencyKey?: string;
35-
expiredAt?: Date;
36-
ttl?: string;
37-
finishedAt?: Date;
38-
startedAt?: Date;
39-
delayedUntil?: Date;
40-
queuedAt?: Date;
41-
metadata?: Record<string, DeserializedJson>;
42-
error?: SerializedError;
43-
isTest: boolean;
44-
isQueued: boolean;
45-
isExecuting: boolean;
46-
isWaiting: boolean;
47-
isCompleted: boolean;
48-
isFailed: boolean;
49-
isSuccess: boolean;
50-
isCancelled: boolean;
51-
realtimeStreams: string[];
52-
}
23+
id: string;
24+
taskIdentifier: TRunTypes["taskIdentifier"];
25+
payload: TRunTypes["payload"];
26+
output?: TRunTypes["output"];
27+
createdAt: Date;
28+
updatedAt: Date;
29+
status: RunStatus;
30+
durationMs: number;
31+
costInCents: number;
32+
baseCostInCents: number;
33+
tags: string[];
34+
idempotencyKey?: string;
35+
expiredAt?: Date;
36+
ttl?: string;
37+
finishedAt?: Date;
38+
startedAt?: Date;
39+
delayedUntil?: Date;
40+
queuedAt?: Date;
41+
metadata?: Record<string, DeserializedJson>;
42+
error?: SerializedError;
43+
isTest: boolean;
44+
isQueued: boolean;
45+
isExecuting: boolean;
46+
isWaiting: boolean;
47+
isCompleted: boolean;
48+
isFailed: boolean;
49+
isSuccess: boolean;
50+
isCancelled: boolean;
51+
realtimeStreams: string[];
52+
}
5353
: never;
5454

5555
export type AnyRunShape = RunShape<AnyRunTypes>;
@@ -102,9 +102,9 @@ export type StreamPartResult<TRun, TStreams extends Record<string, any>> = {
102102

103103
export type RunWithStreamsResult<TRun, TStreams extends Record<string, any>> =
104104
| {
105-
type: "run";
106-
run: TRun;
107-
}
105+
type: "run";
106+
run: TRun;
107+
}
108108
| StreamPartResult<TRun, TStreams>;
109109

110110
export function runShapeStream<TRunTypes extends AnyRunTypes>(
@@ -297,7 +297,10 @@ export class SSEStreamSubscription implements StreamSubscription {
297297

298298
chunkController.enqueue({
299299
id: record.seq_num.toString(),
300-
chunk: parsedBody.data,
300+
chunk:
301+
typeof parsedBody.data === "string"
302+
? safeParseJSON(parsedBody.data)
303+
: parsedBody.data,
301304
timestamp: record.timestamp,
302305
});
303306
}
@@ -390,7 +393,7 @@ export class SSEStreamSubscriptionFactory implements StreamSubscriptionFactory {
390393
headers?: Record<string, string>;
391394
signal?: AbortSignal;
392395
}
393-
) {}
396+
) { }
394397

395398
createSubscription(
396399
runId: string,
@@ -750,10 +753,10 @@ if (isSafari()) {
750753
function getStreamsFromRunShape(run: AnyRunShape): string[] {
751754
const metadataStreams =
752755
run.metadata &&
753-
"$$streams" in run.metadata &&
754-
Array.isArray(run.metadata.$$streams) &&
755-
run.metadata.$$streams.length > 0 &&
756-
run.metadata.$$streams.every((stream) => typeof stream === "string")
756+
"$$streams" in run.metadata &&
757+
Array.isArray(run.metadata.$$streams) &&
758+
run.metadata.$$streams.length > 0 &&
759+
run.metadata.$$streams.every((stream) => typeof stream === "string")
757760
? run.metadata.$$streams
758761
: undefined;
759762

packages/core/src/v3/build/runtime.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { BuildRuntime } from "../schemas/build.js";
44
import { dedupFlags } from "./flags.js";
55
import { homedir } from "node:os";
66

7+
import { existsSync } from "node:fs";
8+
79
export const DEFAULT_RUNTIME = "node" satisfies BuildRuntime;
810

911
export function binaryForRuntime(runtime: BuildRuntime): string {
@@ -25,14 +27,28 @@ export function execPathForRuntime(runtime: BuildRuntime): string {
2527
return process.execPath;
2628
case "bun":
2729
if (typeof process.env.BUN_INSTALL === "string") {
28-
return join(process.env.BUN_INSTALL, "bin", "bun");
30+
const binPath = join(process.env.BUN_INSTALL, "bin", "bun");
31+
32+
if (existsSync(binPath)) {
33+
return binPath;
34+
}
2935
}
3036

3137
if (typeof process.env.BUN_INSTALL_BIN === "string") {
32-
return join(process.env.BUN_INSTALL_BIN, "bun");
38+
const binPath = join(process.env.BUN_INSTALL_BIN, "bun");
39+
40+
if (existsSync(binPath)) {
41+
return binPath;
42+
}
3343
}
3444

35-
return join(homedir(), ".bun", "bin", "bun");
45+
const defaultPath = join(homedir(), ".bun", "bin", "bun");
46+
47+
if (existsSync(defaultPath)) {
48+
return defaultPath;
49+
}
50+
51+
return "bun";
3652
default:
3753
throw new Error(`Unsupported runtime ${runtime}`);
3854
}

0 commit comments

Comments
 (0)