Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions .github/workflows/functional-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ concurrency:

jobs:
functional-tests:
if: github.ref == 'refs/heads/main'
if: github.ref == 'refs/heads/main' || github.event_name == 'workflow_dispatch'
timeout-minutes: 15
runs-on: ubuntu-24.04
steps:
Expand Down Expand Up @@ -47,4 +47,12 @@ jobs:
- name: Run functional tests
env:
PPLX_API_TOKEN: ${{ secrets.PPLX_API_TOKEN }}
run: bazel test //e2e:live --test_env=PPLX_API_TOKEN
run: |
mapfile -t functional_tests < <(
bazel query 'attr(tags, functional_test, tests(//e2e/...))' --output=label
)
if (( ${#functional_tests[@]} == 0 )); then
echo 'No functional tests found' >&2
exit 1
fi
bazel test "${functional_tests[@]}" --test_env=PPLX_API_TOKEN
16 changes: 1 addition & 15 deletions e2e/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,6 @@ js_test(
tags = ["manual"],
)

js_test(
name = "live",
data = [
":typecheck",
"//:node_modules/@perplexity-ai/perplexity_ai",
"//:node_modules/published-sdk",
],
entry_point = "live.spec.ts",
tags = ["manual"],
)

ts_project(
name = "typecheck",
testonly = True,
Expand All @@ -74,10 +63,7 @@ ts_project(

ts_test(
name = "e2e_test",
srcs = [
"live.spec.ts",
"sdk-parity.spec.ts",
],
srcs = ["sdk-parity.spec.ts"],
tags = ["manual"],
tsconfig_types = ["node"],
deps = [
Expand Down
61 changes: 61 additions & 0 deletions e2e/live/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
load("@aspect_rules_ts//ts:defs.bzl", "ts_project")
load("//:ts.bzl", "ts_library", "ts_test")
load("//:tsconfig.bzl", "BASE_COMPILER_OPTIONS")
load(":live_tests.bzl", "live_tests")

package(default_visibility = ["//visibility:private"])

live_tests()

ts_project(
name = "typecheck",
testonly = True,
srcs = [":live_test_sources"],
no_emit = True,
tags = ["manual"],
tsc = "//:tsc",
tsconfig = {
"compilerOptions": dict(
BASE_COMPILER_OPTIONS,
module = "ESNext",
moduleResolution = "Bundler",
types = ["node"],
),
},
deps = [
"//:node_modules/@perplexity-ai/perplexity_ai",
"//:node_modules/@types/node",
"//:node_modules/published-sdk",
],
)

ts_test(
name = "live_test",
srcs = [
"async-chat-completion.spec.ts",
"chat-completion.spec.ts",
"contextualized-embeddings.spec.ts",
"embeddings.spec.ts",
"responses.spec.ts",
"search.spec.ts",
"streaming-chat.spec.ts",
"streaming-responses.spec.ts",
],
tags = ["manual"],
tsconfig_types = ["node"],
deps = [
":live",
"//:node_modules/@types/node",
],
)

ts_library(
name = "live",
srcs = ["helpers.ts"],
tsconfig_types = ["node"],
visibility = ["//visibility:public"],
deps = [
"//:node_modules/@types/node",
"//:node_modules/published-sdk",
],
)
31 changes: 31 additions & 0 deletions e2e/live/async-chat-completion.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import assert from 'node:assert/strict';
import { it } from 'node:test';
import { asyncCompletionContract, createClients, pollAsyncCompletion } from './helpers.ts';

it('matches published async chat completion lifecycle', { timeout: 180_000 }, async () => {
const { candidate, published } = createClients();
const request = {
request: {
max_tokens: 16,
messages: [{ content: 'Reply with only the word pong.', role: 'user' as const }],
model: 'sonar-deep-research',
},
};
const [candidateInitial, publishedInitial] = await Promise.all([
candidate.async.chat.completions.create(request),
published.async.chat.completions.create(request),
]);
assert.deepStrictEqual(
asyncCompletionContract(candidateInitial),
asyncCompletionContract(publishedInitial),
);

const [candidateCompleted, publishedCompleted] = await Promise.all([
pollAsyncCompletion(candidateInitial, (id) => candidate.async.chat.completions.get(id)),
pollAsyncCompletion(publishedInitial, (id) => published.async.chat.completions.get(id)),
]);
assert.deepStrictEqual(
asyncCompletionContract(candidateCompleted),
asyncCompletionContract(publishedCompleted),
);
});
18 changes: 18 additions & 0 deletions e2e/live/chat-completion.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { it } from 'node:test';
import { completionContract, createClients, expectMatchingContracts } from './helpers.ts';

it('matches published chat completion response contract', async () => {
const { candidate, published } = createClients();
const request = {
max_tokens: 16,
messages: [{ content: 'Reply with only the word pong.', role: 'user' as const }],
model: 'sonar',
temperature: 0,
};

await expectMatchingContracts(
() => candidate.chat.completions.create(request),
() => published.chat.completions.create(request),
completionContract,
);
});
17 changes: 17 additions & 0 deletions e2e/live/contextualized-embeddings.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { it } from 'node:test';
import { contextualizedEmbeddingContract, createClients, expectMatchingContracts } from './helpers.ts';

it('matches published contextualized embeddings response contract', async () => {
const { candidate, published } = createClients();
const request = {
dimensions: 128,
input: [['Perplexity answers questions.', 'Its answers include citations.']],
model: 'pplx-embed-context-v1-0.6b' as const,
};

await expectMatchingContracts(
() => candidate.contextualizedEmbeddings.create(request),
() => published.contextualizedEmbeddings.create(request),
contextualizedEmbeddingContract,
);
});
17 changes: 17 additions & 0 deletions e2e/live/embeddings.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { it } from 'node:test';
import { createClients, embeddingContract, expectMatchingContracts } from './helpers.ts';

it('matches published embeddings response contract', async () => {
const { candidate, published } = createClients();
const request = {
dimensions: 128,
input: 'Perplexity answers questions.',
model: 'pplx-embed-v1-0.6b' as const,
};

await expectMatchingContracts(
() => candidate.embeddings.create(request),
() => published.embeddings.create(request),
embeddingContract,
);
});
Loading
Loading