:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(hog): add error-tracking upload with byte parity against posthog-cli (#124526)
Rafael Audibertd1e5adad2834
diff --git a/cli/examples/hog_parity_oracle.rs b/cli/examples/hog_parity_oracle.rsnew file mode 100644index 000000000000..876cad9e0793--- /dev/null+++ b/cli/examples/hog_parity_oracle.rs@@ -0,0 +1,43 @@+//! Reference outputs for hog's byte-parity tests.+//!+//! hog (the TypeScript CLI in `hog/`) must upload the same bytes and content hashes as this crate,+//! or PostHog rejects re-uploads with `content_hash_mismatch`. This example runs the crate's own code+//! with the crate's own Cargo.lock, so the goldens it prints come from exactly what posthog-cli ships.+//! `hog/test/parity/README.md` explains how to regenerate the goldens with it.+//!+//! Usage:+//! cargo run --release --example hog_parity_oracle -- container <type> <file> [<out>]+//! Prints the SHA-512 content hash of the container for <file>, and writes the container to <out>+//! when given. <type> is one of: proguard, hermes, dsym, elf.+//! cargo run --release --example hog_parity_oracle -- release-hash <name> <version>++use posthog_cli::utils::files::content_hash;+use posthog_symbol_data::{write_symbol_data, AppleDsym, ElfDebugInfo, HermesMap, ProguardMapping};++fn main() {+ // nosemgrep: rust.lang.security.args.args -- a local test tool, argv only names fixture files+ let args: Vec<String> = std::env::args().collect();+ match args.get(1).map(String::as_str) {+ Some("container") => {+ let input = std::fs::read(&args[3]).expect("read input");+ let data = match args[2].as_str() {+ "proguard" => write_symbol_data(ProguardMapping {+ content: String::from_utf8(input).expect("utf-8 mapping"),+ }),+ "hermes" => write_symbol_data(HermesMap {+ sourcemap: String::from_utf8(input).expect("utf-8 map"),+ }),+ "dsym" => write_symbol_data(AppleDsym { data: input }),+ "elf" => write_symbol_data(ElfDebugInfo { data: input }),+ other => panic!("unknown container type {other}"),+ }+ .expect("write symbol data");+ println!("{}", content_hash([&data]));+ if let Some(out) = args.get(4) {+ std::fs::write(out, &data).expect("write container");+ }+ }+ Some("release-hash") => println!("{}", content_hash([args[2].as_bytes(), args[3].as_bytes()])),+ _ => panic!("usage: hog_parity_oracle container <type> <file> [<out>] | release-hash <name> <version>"),+ }+}diff --git a/hog/AGENTS.md b/hog/AGENTS.mdindex 4521349be5b5..9dcd495bc297 100644--- a/hog/AGENTS.md+++ b/hog/AGENTS.md@@ -4,13 +4,15 @@## Layout-| Path | Holds |-| ---------------- | -------------------------------------------------------------------------------------------------------------------------------------------- |-| `src/commands/` | One file per command. `index.ts` is the tree of every command; `legacy.ts` holds the ones posthog-cli still owns |-| `src/core/` | The shared parts every command uses: command definitions, context and global options, output, agent detection, errors, runtime, the manifest |-| `src/posthog/` | The PostHog API client and credentials |-| `src/cli.ts` | Turns the command tree into a commander program, runs it, and maps errors to exit codes |-| `src/testing.ts` | `runHog` and a fake runtime, so tests run the real CLI without a process or a network |+| Path | Holds |+| --------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- |+| `src/commands/` | One file per command. `index.ts` is the tree of every command; `legacy.ts` holds the ones posthog-cli still owns |+| `src/core/` | The shared parts every command uses: command definitions, context and global options, output, agent detection, errors, runtime, the manifest |+| `src/posthog/` | The PostHog API client and credentials |+| `src/error-tracking/` | Symbol upload: discovery, artifact types under `kinds/`, the container and content hash, releases, git, the upload protocol |+| `test/parity/` | Goldens recorded from posthog-cli and the tests that hold hog to them. Read its README before changing anything that reaches an upload |+| `src/cli.ts` | Turns the command tree into a commander program, runs it, and maps errors to exit codes |+| `src/testing.ts` | `runHog` and a fake runtime, so tests run the real CLI without a process or a network |Import from another folder with `@/`, which `tsconfig.json` maps to `src/`, as in `import { defineCommand } from '@/core/command'`. Use `./` only inside the same folder.@@ -58,4 +60,6 @@ export default defineCommand({- Commands reach the outside world only through `ctx` (`ctx.posthog()`, `ctx.runtime`), so tests can fake it. Do not read `process` or call `fetch` directly.- Import heavy dependencies inside `run` with `await import()`. Every command module loads on every call, so a top-level import of a large library slows down all commands.- Declare `scopes`. `hog commands` lists them for agents, and a 403 names them in its hint.+- `hog error-tracking` must upload the same bytes, content hashes and requests as posthog-cli, or re-uploads fail with `content_hash_mismatch`. A change to anything that reaches an upload keeps `test/parity/` green, and a new artifact type or flag adds parity scenarios recorded from posthog-cli.+- Code under `src/error-tracking/` reads build output with `node:fs` directly, because it walks real folders. Its tests use temporary folders instead of `ctx.runtime` files.- Every string a person reads follows `/writing-user-facing-copy`: sentence case, no em dashes.diff --git a/hog/README.md b/hog/README.mdindex 1d6424a902e5..832df579ee3d 100644--- a/hog/README.md+++ b/hog/README.md@@ -11,15 +11,17 @@ It is not published yet.`hog` has no `exp` namespace.The commands `posthog-cli` keeps under `exp` (`query`, `endpoints`, `logs`, `tasks`, `schema`) are top-level commands in `hog`.-| Command | Status |-| ------------------------- | ----------------------------------------------------------------------------------------------------------------------- |-| `hog auth login` | Logs in through the browser and saves a personal API key. Agents finish with `hog auth login --wait`. |-| `hog auth status` | Shows whether hog is logged in, whose key it is, and where the key comes from. Exits with code 1 without a working key. |-| `hog auth logout` | Removes the stored key. The key stays valid in PostHog until you delete it there. |-| `hog query run <query>` | Runs a HogQL query. `-` reads the query from stdin. |-| `hog query check <query>` | Checks a query without running it. Exits with code 1 when the query has errors. |-| `hog commands` | Lists every command, its arguments, options and scopes. |-| Everything else | Not ported yet. Exits with code 1 and prints the `posthog-cli` command to run instead, with the same arguments. |+| Command | Status |+| --------------------------------------- | ----------------------------------------------------------------------------------------------------------------------- |+| `hog auth login` | Logs in through the browser and saves a personal API key. Agents finish with `hog auth login --wait`. |+| `hog auth status` | Shows whether hog is logged in, whose key it is, and where the key comes from. Exits with code 1 without a working key. |+| `hog auth logout` | Removes the stored key. The key stays valid in PostHog until you delete it there. |+| `hog query run <query>` | Runs a HogQL query. `-` reads the query from stdin. |+| `hog query check <query>` | Checks a query without running it. Exits with code 1 when the query has errors. |+| `hog error-tracking upload [paths...]` | Uploads symbols for readable stack traces. ProGuard and R8 mappings so far. `hog et` is an alias. |+| `hog config check`, `hog config schema` | Check `posthog.json` against its schema, or print the schema. |+| `hog commands` | Lists every command, its arguments, options and scopes. |+| Everything else | Not ported yet. Exits with code 1 and prints the `posthog-cli` command to run instead, with the same arguments. |## Agents, people and pipes@@ -35,6 +37,24 @@ The commands `posthog-cli` keeps under `exp` (`query`, `endpoints`, `logs`, `tas`-o text` or `-o json` overrides the default, and `--raw` prints a command's full result as JSON.Exit codes: 0 on success, 1 when a command fails, 2 for a usage error.+## posthog.json++Project settings live in `posthog.json`, which hog looks for from the current folder up to the git root.+It never holds API keys.+Point `$schema` at the published schema to get validation in your editor:++```json+{+ "$schema": "https://raw.githubusercontent.com/PostHog/posthog/master/hog/posthog.schema.json",+ "errorTracking": {+ "release": { "name": "my-app" },+ "sources": [{ "path": "app/build/outputs/mapping/release", "mapId": "<map id>" }]+ }+}+```++`posthog.schema.json` is generated from `src/core/config.ts` with `pnpm --filter @posthog/hog schema`.+## Credentials`hog` reads the same credentials as `posthog-cli`, in the same order:diff --git a/hog/package.json b/hog/package.jsonindex b1a462d3fc08..682c470e70f4 100644--- a/hog/package.json+++ b/hog/package.json@@ -11,12 +11,14 @@"hog": "bun --no-env-file src/index.ts","compile": "bun build --compile --no-compile-autoload-dotenv --no-compile-autoload-bunfig src/index.ts --outfile dist/hog","typecheck": "tsc --noEmit",- "unit": "bun test"+ "unit": "bun test",+ "schema": "bun scripts/write-schema.ts"},"dependencies": {"@clack/prompts": "1.8.1","cli-table3": "0.6.5",- "commander": "15.0.0"+ "commander": "15.0.0",+ "zod": "^4.3.6"},"devDependencies": {"@types/bun": "1.3.14",diff --git a/hog/posthog.schema.json b/hog/posthog.schema.jsonnew file mode 100644index 000000000000..45c94a52b71c--- /dev/null+++ b/hog/posthog.schema.json@@ -0,0 +1,79 @@+{+ "$id": "https://raw.githubusercontent.com/PostHog/posthog/master/hog/posthog.schema.json",+ "$schema": "https://json-schema.org/draft/2020-12/schema",+ "type": "object",+ "properties": {+ "$schema": {+ "description": "The JSON schema for this file.",+ "type": "string"+ },+ "errorTracking": {+ "type": "object",+ "properties": {+ "release": {+ "description": "The release every uploaded symbol set belongs to.",+ "type": "object",+ "properties": {+ "name": {+ "description": "The release name, usually the app or service name.",+ "type": "string",+ "minLength": 1+ },+ "version": {+ "description": "The release version. hog uses the git commit when this is not set.",+ "type": "string",+ "minLength": 1+ }+ },+ "additionalProperties": false+ },+ "sources": {+ "description": "What `hog error-tracking inject`, `upload` and `process` scan when no path is passed.",+ "type": "array",+ "items": {+ "type": "object",+ "properties": {+ "path": {+ "type": "string",+ "minLength": 1,+ "description": "A folder or file to scan, relative to posthog.json."+ },+ "kind": {+ "description": "The artifact type. hog detects it from the files when this is not set.",+ "type": "string",+ "enum": ["js", "hermes", "proguard", "dsym", "elf"]+ },+ "ignore": {+ "description": "Glob patterns of files to skip, relative to `path`.",+ "type": "array",+ "items": {+ "type": "string"+ }+ },+ "mapId": {+ "description": "ProGuard only: the map ID your Android build injected into the app.",+ "type": "string",+ "minLength": 1+ }+ },+ "required": ["path"],+ "additionalProperties": false,+ "description": "A place where the build writes artifacts with symbols, such as bundles and their sourcemaps."+ }+ }+ },+ "additionalProperties": false,+ "description": "Settings for `hog error-tracking`."+ },+ "languages": {+ "description": "Typed SDK settings that `posthog-cli exp schema pull` writes. hog leaves them alone.",+ "type": "object",+ "propertyNames": {+ "type": "string"+ },+ "additionalProperties": {}+ }+ },+ "additionalProperties": false,+ "description": "Settings for the PostHog CLI. Never put API keys here: use `hog auth login` or environment variables."+}diff --git a/hog/scripts/write-schema.ts b/hog/scripts/write-schema.tsnew file mode 100644index 000000000000..bf0408c9481d--- /dev/null+++ b/hog/scripts/write-schema.ts@@ -0,0 +1,8 @@+// Writes posthog.schema.json from the zod definitions in src/core/config.ts. Run `pnpm --filter+// @posthog/hog schema` after changing them; a test fails while the file is out of date.+import { writeFileSync } from 'node:fs'+import { join } from 'node:path'++import { configSchema } from '../src/core/config'++writeFileSync(join(import.meta.dir, '..', 'posthog.schema.json'), `${JSON.stringify(configSchema(), null, 2)}\n`)diff --git a/hog/src/cli.test.ts b/hog/src/cli.test.tsindex 2820c597acac..99b3468f1a2b 100644--- a/hog/src/cli.test.ts+++ b/hog/src/cli.test.ts@@ -82,7 +82,7 @@ describe('hog', () => {const result = await runHog(['commands'], { env: { CLAUDECODE: '1' } })expect(result.exitCode).toBe(0)const manifest = result.json()- expect(manifest).toMatchObject({ cli: 'hog', agent: 'claude-code' })+ expect(manifest).toMatchObject({ cli: 'hog', agent: 'claude-code', aliases: { et: 'error-tracking' } })expect(manifest.globalOptions).toContainEqual(expect.objectContaining({ flags: '-o, --output <format>' }))expect(manifest.commands.find((command: { name: string }) => command.name === 'query run')).toMatchObject({name: 'query run',@@ -96,6 +96,9 @@ describe('hog', () => {'query run','query check','query editor',+ 'error-tracking upload',+ 'config check',+ 'config schema','commands',...Object.keys(LEGACY_COMMANDS),])diff --git a/hog/src/cli.ts b/hog/src/cli.tsindex 88b677c66377..27d61cf93772 100644--- a/hog/src/cli.ts+++ b/hog/src/cli.ts@@ -153,6 +153,7 @@ function createProgram(runtime: Runtime, mode: Mode, state: { exitCode: number }const command = parent.command(name).description(node.description)switch (node.kind) {case 'group':+ command.aliases(node.aliases ?? [])for (const [childName, child] of Object.entries(node.commands)) {addNode(command, childName, child)}diff --git a/hog/src/commands/commands.ts b/hog/src/commands/commands.tsindex 657bd2bfbbef..973f046fda89 100644--- a/hog/src/commands/commands.ts+++ b/hog/src/commands/commands.ts@@ -1,5 +1,5 @@import { defineCommand } from '@/core/command'-import { describeCommands, describeGlobalOptions } from '@/core/manifest'+import { describeAliases, describeCommands, describeGlobalOptions } from '@/core/manifest'import { VERSION } from '@/version'export default defineCommand({@@ -14,6 +14,7 @@ export default defineCommand({agentReason: ctx.mode.agentReason,globalOptions: describeGlobalOptions(),commands: describeCommands(ctx.tree),+ aliases: describeAliases(ctx.tree),}),human({ result, out }) {diff --git a/hog/src/commands/config/check.ts b/hog/src/commands/config/check.tsnew file mode 100644index 000000000000..c60e456b7c5a--- /dev/null+++ b/hog/src/commands/config/check.ts@@ -0,0 +1,40 @@+import { defineCommand } from '@/core/command'+import { CONFIG_FILE, findConfig, validateConfig, type ConfigProblem } from '@/core/config'++type CheckResult =+ | { status: 'missing'; next: string }+ | { status: 'valid'; path: string }+ | { status: 'invalid'; path: string; problems: ConfigProblem[] }++export default defineCommand({+ description: 'Check posthog.json against its schema and list every problem',+ notes: `hog looks for ${CONFIG_FILE} in the current folder, then in each parent up to the git root. Exits with code 1 when the file is missing or has problems.`,+ examples: ['hog config check'],++ async run({ ctx }): Promise<CheckResult> {+ const path = await findConfig(ctx.runtime)+ if (path === undefined) {+ return { status: 'missing', next: 'hog config schema' }+ }+ const { problems } = validateConfig(await ctx.runtime.readFile(path))+ return problems.length === 0 ? { status: 'valid', path } : { status: 'invalid', path, problems }+ },++ human({ result, out }) {+ if (result.status === 'missing') {+ out.line(out.style(`No ${CONFIG_FILE} between here and the git root.`, 'yellow', 'bold'))+ out.line(`Run ${out.style(result.next, 'bold')} to see what it can hold.`)+ return+ }+ if (result.status === 'valid') {+ out.line(`${out.style('Valid', 'green', 'bold')}: ${result.path}`)+ return+ }+ out.line(`${out.style('Invalid', 'red', 'bold')}: ${result.path}`)+ for (const problem of result.problems) {+ out.line(` ${out.style(problem.path || '(root)', 'bold')} ${problem.message}`)+ }+ },++ exitCode: (result) => (result.status === 'valid' ? 0 : 1),+})diff --git a/hog/src/commands/config/config.test.ts b/hog/src/commands/config/config.test.tsnew file mode 100644index 000000000000..609208c3f4e2--- /dev/null+++ b/hog/src/commands/config/config.test.ts@@ -0,0 +1,52 @@+import { describe, expect, test } from 'bun:test'+import { readFileSync } from 'node:fs'+import { join } from 'node:path'++import { configSchema } from '@/core/config'+import { runHog } from '@/testing'++const VALID = JSON.stringify({ errorTracking: { sources: [{ path: 'dist', kind: 'js' }] } })++describe('hog config', () => {+ test('posthog.schema.json matches the zod definitions', () => {+ const file = JSON.parse(readFileSync(join(import.meta.dir, '../../../posthog.schema.json'), 'utf8'))+ expect(file).toEqual(configSchema())+ })++ test.each([+ [+ 'a valid file in the working folder',+ { '/work/posthog.json': VALID },+ 0,+ { status: 'valid', path: '/work/posthog.json' },+ ],+ ['a file in a parent folder', { '/posthog.json': VALID }, 0, { status: 'valid', path: '/posthog.json' }],+ [+ 'no file up to the git root',+ { '/work/.git/HEAD': 'ref: refs/heads/main', '/posthog.json': VALID },+ 1,+ { status: 'missing' },+ ],+ [+ 'a typo and a wrong kind',+ {+ '/work/posthog.json': JSON.stringify({+ errorTraking: {},+ errorTracking: { sources: [{ path: 'x', kind: 'java' }] },+ }),+ },+ 1,+ {+ status: 'invalid',+ problems: [+ expect.objectContaining({ path: 'errorTracking.sources[0].kind' }),+ expect.objectContaining({ path: '' }),+ ],+ },+ ],+ ])('check: %s', async (_name, files, exitCode, expected) => {+ const result = await runHog(['config', 'check'], { env: { CLAUDECODE: '1' }, files })+ expect(result.exitCode).toBe(exitCode)+ expect(result.json()).toMatchObject(expected)+ })+})diff --git a/hog/src/commands/config/index.ts b/hog/src/commands/config/index.tsnew file mode 100644index 000000000000..a57ca8abb217--- /dev/null+++ b/hog/src/commands/config/index.ts@@ -0,0 +1,9 @@+import { defineGroup } from '@/core/command'++import check from './check'+import schema from './schema'++export default defineGroup({+ description: 'Check posthog.json, the project settings file hog reads',+ commands: { check, schema },+})diff --git a/hog/src/commands/config/schema.ts b/hog/src/commands/config/schema.tsnew file mode 100644index 000000000000..360d6ab08c80--- /dev/null+++ b/hog/src/commands/config/schema.ts@@ -0,0 +1,10 @@+import { defineCommand } from '@/core/command'+import { configSchema, SCHEMA_URL } from '@/core/config'++export default defineCommand({+ description: 'Print the JSON schema for posthog.json',+ notes: `Editors validate posthog.json when it starts with "$schema": "${SCHEMA_URL}".`,+ examples: ['hog config schema > posthog.schema.json'],++ run: () => configSchema(),+})diff --git a/hog/src/commands/error-tracking/error-tracking.test.ts b/hog/src/commands/error-tracking/error-tracking.test.tsnew file mode 100644index 000000000000..bee6f8ba5c38--- /dev/null+++ b/hog/src/commands/error-tracking/error-tracking.test.ts@@ -0,0 +1,90 @@+import { describe, expect, test } from 'bun:test'+import { mkdirSync, mkdtempSync, symlinkSync, writeFileSync } from 'node:fs'+import { tmpdir } from 'node:os'+import { join } from 'node:path'++import { contentHash, SymbolDataType, writeSymbolData } from '@/error-tracking/container'+import { runHog } from '@/testing'++import { GIT_REPO, SMALL_MAPPING } from '../../../test/parity/fixtures'++function project(files: Record<string, string>): string {+ const folder = mkdtempSync(join(tmpdir(), 'hog-et-'))+ for (const [path, contents] of Object.entries(files)) {+ mkdirSync(join(folder, path, '..'), { recursive: true })+ writeFileSync(join(folder, path), contents)+ }+ return folder+}++describe('hog error-tracking upload', () => {+ test.each([+ ['the map ID from posthog.json', [], 'map-1'],+ ['--map-id over the one in posthog.json', ['--map-id', 'map-2'], 'map-2'],+ ])('--dry-run plans uploads from posthog.json without credentials, with %s', async (_name, flags, chunkId) => {+ const folder = project({+ 'posthog.json': JSON.stringify({+ errorTracking: {+ release: { name: 'app', version: '2.0' },+ sources: [{ path: 'build', mapId: 'map-1' }],+ },+ }),+ 'build/mapping.txt': SMALL_MAPPING,+ 'build/notes.txt': 'not a mapping',+ })+ const result = await runHog(['et', 'upload', '--dry-run', ...flags], {+ env: { CLAUDECODE: '1' },+ cwd: folder,+ useDisk: true,+ })++ expect(result.exitCode).toBe(0)+ expect(result.json()).toEqual({+ dryRun: true,+ release: { name: 'app', version: '2.0', id: null },+ symbolSets: [+ {+ path: 'build/mapping.txt',+ kind: 'proguard',+ chunkId,+ contentHash: contentHash(+ writeSymbolData(SymbolDataType.ProguardMapping, Buffer.from(SMALL_MAPPING))+ ),+ size: expect.any(Number),+ status: 'planned',+ },+ ],+ })+ })++ test('--dry-run reads the release from the repository a symlinked mapping points into', async () => {+ const repository = project({ ...GIT_REPO, 'app/mapping.txt': SMALL_MAPPING })+ const outside = project({})+ symlinkSync(join(repository, 'app/mapping.txt'), join(outside, 'mapping.txt'))+ const result = await runHog(['et', 'upload', '--dry-run', 'mapping.txt', '--map-id', 'map-1'], {+ env: { CLAUDECODE: '1' },+ cwd: outside,+ useDisk: true,+ })+ expect(result.json().release).toEqual({+ name: 'example-app',+ version: 'c0ffee00c0ffee00c0ffee00c0ffee00c0ffee00',+ id: null,+ })+ })++ test.each([+ ['a ProGuard mapping without a map ID', ['mapping.txt'], 2, 'map_id_required'],+ ['a file hog cannot place', ['notes.txt'], 1, 'unknown_artifact'],+ ['no paths and no posthog.json', [], 2, 'no_paths'],+ ])('%s fails with a hint', async (_name, paths, exitCode, code) => {+ const folder = project({ 'mapping.txt': SMALL_MAPPING, 'notes.txt': 'hello' })+ const result = await runHog(['et', 'upload', '--dry-run', ...paths], {+ env: { CLAUDECODE: '1' },+ cwd: folder,+ useDisk: true,+ })+ expect(result.exitCode).toBe(exitCode)+ expect(result.error()).toMatchObject({ code, hint: expect.any(String) })+ })+})diff --git a/hog/src/commands/error-tracking/index.ts b/hog/src/commands/error-tracking/index.tsnew file mode 100644index 000000000000..3af7720d85e5--- /dev/null+++ b/hog/src/commands/error-tracking/index.ts@@ -0,0 +1,9 @@+import { defineGroup } from '@/core/command'++import upload from './upload'++export default defineGroup({+ description: 'Upload symbols for readable stack traces in error tracking',+ aliases: ['et'],+ commands: { upload },+})diff --git a/hog/src/commands/error-tracking/upload.ts b/hog/src/commands/error-tracking/upload.tsnew file mode 100644index 000000000000..33474f2af94f--- /dev/null+++ b/hog/src/commands/error-tracking/upload.ts@@ -0,0 +1,259 @@+import { realpathSync } from 'node:fs'+import { dirname } from 'node:path'++import { defineCommand } from '@/core/command'+import { ARTIFACT_KINDS } from '@/core/config'+import type { Context } from '@/core/context'+import { EXIT_USAGE, HogError } from '@/core/errors'+import { plural } from '@/core/text'+import { contentHash } from '@/error-tracking/container'+import { discover, type Artifact, type Root } from '@/error-tracking/discover'+import { GitError, gitInfo, type GitInfo } from '@/error-tracking/git'+import { proguardContainer } from '@/error-tracking/kinds/proguard'+import { fetchOrCreateRelease, resolveRelease, type Release } from '@/error-tracking/release'+import { SymbolSetClient, type SymbolSetUpload, type UploadStatus } from '@/error-tracking/upload'++interface PlannedSymbolSet {+ path: string+ kind: string+ chunkId: string+ contentHash: string+ size: number+ status: UploadStatus | 'planned'+}++interface UploadResult {+ dryRun: boolean+ release: { name: string; version: string; id: string | null } | null+ symbolSets: PlannedSymbolSet[]+}++interface Prepared {+ artifact: Artifact+ upload: SymbolSetUpload+}++function prepare(artifact: Artifact, mapId: string | undefined): Prepared {+ // ProGuard mappings carry no id of their own: the Android build plugin writes one into the app,+ // and the same value must be passed here.+ const chunkId = mapId ?? artifact.root.mapId+ if (!chunkId) {+ throw new HogError(+ 'map_id_required',+ `${artifact.display} is a ProGuard mapping, which needs the map ID your build injected into the app.`,+ 'Pass --map-id, or set "mapId" on the source in posthog.json.',+ EXIT_USAGE+ )+ }+ return { artifact, upload: { chunkId, releaseId: null, data: proguardContainer(artifact.path, artifact.display) } }+}++async function roots(+ ctx: Context,+ paths: string[],+ kind: Root['kind'],+ mapId: string | undefined+): Promise<{ roots: Root[]; cwd: string }> {+ if (paths.length > 0) {+ return { roots: paths.map((path) => ({ path, kind, mapId })), cwd: ctx.runtime.cwd() }+ }+ const loaded = await ctx.config()+ const sources = loaded?.config.errorTracking?.sources ?? []+ if (!loaded || sources.length === 0) {+ throw new HogError(+ 'no_paths',+ 'Pass the files or folders to upload, or list them under errorTracking.sources in posthog.json.',+ 'Run `hog config schema` to see the posthog.json format.',+ EXIT_USAGE+ )+ }+ return { roots: sources.map((source) => ({ ...source, kind: kind ?? source.kind })), cwd: loaded.root }+}++function releaseGit(ctx: Context, artifacts: Artifact[]): GitInfo | undefined {+ const first = artifacts[0]+ if (!first) {+ return undefined+ }+ try {+ // posthog-cli resolves symlinks first, so a link outside the repository still finds it.+ return gitInfo(ctx.runtime.env, dirname(realpathSync(first.path)))+ } catch (error) {+ if (error instanceof GitError) {+ throw new HogError(+ 'git_failed',+ `hog couldn't read the git repository: ${error.message}`,+ 'Pass --release-name and --release-version.'+ )+ }+ throw error+ }+}++export default defineCommand({+ description: 'Upload symbols so PostHog can show readable stack traces',+ args: {+ paths: {+ description: 'Files or folders to upload. Defaults to errorTracking.sources in posthog.json',+ optional: true,+ variadic: true,+ },+ },+ options: {+ kind: {+ type: 'string',+ choices: ARTIFACT_KINDS,+ description: 'The artifact type, when hog should not detect it',+ },+ mapId: {+ type: 'string',+ placeholder: 'id',+ description: 'ProGuard only: the map ID your Android build injected into the app',+ },+ releaseName: {+ type: 'string',+ placeholder: 'name',+ description: 'The release name. Defaults to the git repository name',+ },+ releaseVersion: {+ type: 'string',+ placeholder: 'version',+ description: 'The release version. Defaults to the git commit',+ },+ build: {+ type: 'string',+ placeholder: 'build',+ description: 'A build number, added to the version as version+build',+ },+ force: { type: 'boolean', description: 'Replace symbol sets PostHog already has with different content' },+ skipOnConflict: { type: 'boolean', description: 'Keep symbol sets PostHog already has with different content' },+ batchSize: { type: 'string', placeholder: 'count', description: 'Symbol sets per upload request (default 50)' },+ dryRun: {+ type: 'boolean',+ description: 'Show what would be uploaded, with content hashes, without contacting PostHog',+ },+ },+ scopes: ['error_tracking:write'],+ notes: [+ "hog finds the artifacts in each path and detects their type from the files. A file it can't place, or one that two types could claim, is an error that names --kind.",+ 'Supported: ProGuard and R8 mappings (mapping.txt).',+ ].join('\n'),+ examples: [+ 'hog error-tracking upload app/build/outputs/mapping/release --map-id "$MAP_ID"',+ 'hog et upload --dry-run',+ ],++ async run({ args, options, ctx }): Promise<UploadResult> {+ if (options.force && options.skipOnConflict) {+ throw new HogError(+ 'usage_error',+ '--force and --skip-on-conflict cannot be used together.',+ undefined,+ EXIT_USAGE+ )+ }+ const batchSize = options.batchSize === undefined ? 50 : Number(options.batchSize)+ if (!Number.isInteger(batchSize) || batchSize < 1) {+ throw new HogError(+ 'usage_error',+ '--batch-size must be a whole number of at least 1.',+ undefined,+ EXIT_USAGE+ )+ }+ const { roots: found, cwd } = await roots(ctx, args.paths ?? [], options.kind, options.mapId)+ const artifacts = discover(found, cwd)+ if (artifacts.length === 0) {+ throw new HogError(+ 'nothing_to_upload',+ 'hog found no artifacts to upload in those paths.',+ 'Check the paths, or pass --kind.'+ )+ }+ const prepared = artifacts.map((artifact) => prepare(artifact, options.mapId))+ const duplicate = prepared.find(+ (item, index) => prepared.findIndex((other) => other.upload.chunkId === item.upload.chunkId) !== index+ )+ if (duplicate) {+ throw new HogError(+ 'duplicate_chunk_id',+ `Two artifacts share the chunk ID ${duplicate.upload.chunkId}.`,+ 'Give each mapping its own --map-id.'+ )+ }++ const config = (await ctx.config())?.config.errorTracking?.release+ const git = releaseGit(ctx, artifacts)+ const { name, version } = resolveRelease(+ {+ name: options.releaseName ?? config?.name,+ version: options.releaseVersion ?? config?.version,+ build: options.build,+ },+ git+ )++ const describe = (item: Prepared, status: PlannedSymbolSet['status']): PlannedSymbolSet => ({+ path: item.artifact.display,+ kind: item.artifact.kind,+ chunkId: item.upload.chunkId,+ contentHash: item.upload.contentHash ?? contentHash(item.upload.data),+ size: item.upload.data.length,+ status,+ })+ const release = name !== undefined && version !== undefined ? { name, version } : undefined+ if (options.dryRun) {+ return {+ dryRun: true,+ release: release ? { ...release, id: null } : null,+ symbolSets: prepared.map((item) => describe(item, 'planned')),+ }+ }++ const client = new SymbolSetClient(ctx.runtime, await ctx.credentials())+ let created: Release | undefined+ if (release) {+ created = await fetchOrCreateRelease(client, release.name, release.version, git ? { git } : {})+ }+ const uploads = prepared.map((item) => ({ ...item.upload, releaseId: created?.id ?? null }))+ const outcome = await client.upload(uploads, {+ batchSize,+ force: options.force === true,+ skipOnConflict: options.skipOnConflict === true,+ })+ return {+ dryRun: false,+ release: release ? { ...release, id: created?.id ?? null } : null,+ symbolSets: prepared.map((item) =>+ describe(item, outcome.status.get(item.upload.chunkId) ?? 'already_present')+ ),+ }+ },++ human({ result, out }) {+ if (result.release) {+ out.line(`Release ${out.style(`${result.release.name}@${result.release.version}`, 'bold')}`)+ }+ out.table(+ [+ { name: 'path' },+ { name: 'kind' },+ { name: 'chunk id' },+ { name: 'size', kind: 'number' },+ { name: 'status' },+ ],+ result.symbolSets.map((set) => [set.path, set.kind, set.chunkId, set.size, set.status.replace('_', ' ')])+ )+ const uploaded = result.symbolSets.filter((set) => set.status === 'uploaded').length+ const present = result.symbolSets.filter((set) => set.status === 'already_present').length+ const tooLarge = result.symbolSets.filter((set) => set.status === 'too_large').length+ out.line(+ out.style(+ result.dryRun+ ? `Dry run: ${plural(result.symbolSets.length, 'symbol set')} would be uploaded. Nothing was sent.`+ : `${plural(uploaded, 'symbol set')} uploaded, ${present} already present${tooLarge ? `, ${tooLarge} too large` : ''}.`,+ 'dim'+ )+ )+ },+})diff --git a/hog/src/commands/index.ts b/hog/src/commands/index.tsindex c064f9843232..edf798ea2b7a 100644--- a/hog/src/commands/index.ts+++ b/hog/src/commands/index.ts@@ -2,12 +2,16 @@ import type { CommandTree } from '@/core/command'import auth from './auth'import commands from './commands'+import config from './config'+import errorTracking from './error-tracking'import { LEGACY_COMMANDS } from './legacy'import query from './query'export const COMMANDS: CommandTree = {auth,query,+ 'error-tracking': errorTracking,+ config,commands,...LEGACY_COMMANDS,}diff --git a/hog/src/core/command.ts b/hog/src/core/command.tsindex c3ac5845d943..44b30b639e51 100644--- a/hog/src/core/command.ts+++ b/hog/src/core/command.ts@@ -5,6 +5,8 @@ import { kebabCase } from './text'export interface ArgumentSpec {description: stringoptional?: boolean+ // Collects every remaining argument into a list. Only the last argument can be variadic.+ variadic?: boolean// `-` reads the value from stdin, and an empty value is an error.stdin?: boolean}@@ -21,7 +23,11 @@ export type OptionSpec =}type ArgumentValues<Args> = {- [Name in keyof Args]: Args[Name] extends { optional: true } ? string | undefined : string+ [Name in keyof Args]: Args[Name] extends { variadic: true }+ ? string[]+ : Args[Name] extends { optional: true }+ ? string | undefined+ : string}export type OptionValues<Options> = {@@ -73,6 +79,8 @@ export interface Group {kind: 'group'description: stringcommands: CommandTree+ // Shorter names that work the same, like `et` for `error-tracking`. Help and agents use the full name.+ aliases?: readonly string[]}// A command posthog-cli still owns. hog lists it and points the caller to `use`, with the same arguments.@@ -107,5 +115,6 @@ export function optionFlags(name: string, spec: OptionSpec): string {}export function argumentSyntax(name: string, spec: ArgumentSpec): string {- return spec.optional ? `[${kebabCase(name)}]` : `<${kebabCase(name)}>`+ const label = `${kebabCase(name)}${spec.variadic ? '...' : ''}`+ return spec.optional ? `[${label}]` : `<${label}>`}diff --git a/hog/src/core/config.ts b/hog/src/core/config.tsnew file mode 100644index 000000000000..d7b435b378c8--- /dev/null+++ b/hog/src/core/config.ts@@ -0,0 +1,135 @@+import { dirname, join } from 'node:path'+import { z } from 'zod'++import { HogError } from './errors'+import type { Runtime } from './runtime'++export const CONFIG_FILE = 'posthog.json'++// Where editors fetch the schema from. The file is generated from `PostHogConfig` and checked in.+export const SCHEMA_URL = 'https://raw.githubusercontent.com/PostHog/posthog/master/hog/posthog.schema.json'++export const ARTIFACT_KINDS = ['js', 'hermes', 'proguard', 'dsym', 'elf'] as const+export type ArtifactKind = (typeof ARTIFACT_KINDS)[number]++const Source = z+ .strictObject({+ path: z.string().min(1).describe('A folder or file to scan, relative to posthog.json.'),+ kind: z+ .enum(ARTIFACT_KINDS)+ .optional()+ .describe('The artifact type. hog detects it from the files when this is not set.'),+ ignore: z.array(z.string()).optional().describe('Glob patterns of files to skip, relative to `path`.'),+ mapId: z+ .string()+ .min(1)+ .optional()+ .describe('ProGuard only: the map ID your Android build injected into the app.'),+ })+ .describe('A place where the build writes artifacts with symbols, such as bundles and their sourcemaps.')++const ErrorTracking = z+ .strictObject({+ release: z+ .strictObject({+ name: z.string().min(1).optional().describe('The release name, usually the app or service name.'),+ version: z+ .string()+ .min(1)+ .optional()+ .describe('The release version. hog uses the git commit when this is not set.'),+ })+ .optional()+ .describe('The release every uploaded symbol set belongs to.'),+ sources: z+ .array(Source)+ .optional()+ .describe('What `hog error-tracking inject`, `upload` and `process` scan when no path is passed.'),+ })+ .describe('Settings for `hog error-tracking`.')++export const PostHogConfig = z+ .strictObject({+ $schema: z.string().optional().describe('The JSON schema for this file.'),+ errorTracking: ErrorTracking.optional(),+ languages: z+ .record(z.string(), z.unknown())+ .optional()+ .describe('Typed SDK settings that `posthog-cli exp schema pull` writes. hog leaves them alone.'),+ })+ .describe('Settings for the PostHog CLI. Never put API keys here: use `hog auth login` or environment variables.')++export type PostHogConfig = z.infer<typeof PostHogConfig>++export interface LoadedConfig {+ path: string+ // Relative paths in the file resolve from this folder.+ root: string+ config: PostHogConfig+}++export interface ConfigProblem {+ path: string+ message: string+}++export function configSchema(): Record<string, unknown> {+ return { $id: SCHEMA_URL, ...z.toJSONSchema(PostHogConfig, { target: 'draft-2020-12' }) }+}++export async function findConfig(runtime: Runtime): Promise<string | undefined> {+ let folder = runtime.cwd()+ for (;;) {+ const candidate = join(folder, CONFIG_FILE)+ if (await runtime.exists(candidate)) {+ return candidate+ }+ const parent = dirname(folder)+ if ((await runtime.exists(join(folder, '.git'))) || parent === folder) {+ return undefined+ }+ folder = parent+ }+}++// Returns every problem with the file instead of the first, so `hog config check` can list them all.+export function validateConfig(contents: string): { config?: PostHogConfig; problems: ConfigProblem[] } {+ let raw: unknown+ try {+ raw = JSON.parse(contents)+ } catch (error) {+ return {+ problems: [{ path: '', message: `Not valid JSON: ${error instanceof Error ? error.message : error}` }],+ }+ }+ const parsed = PostHogConfig.safeParse(raw)+ if (parsed.success) {+ return { config: parsed.data, problems: [] }+ }+ return {+ problems: parsed.error.issues.map((issue) => ({+ path: issue.path+ .map((part) => (typeof part === 'number' ? `[${part}]` : `.${String(part)}`))+ .join('')+ .replace(/^\./, ''),+ message: issue.message,+ })),+ }+}++export async function loadConfig(runtime: Runtime): Promise<LoadedConfig | undefined> {+ const path = await findConfig(runtime)+ if (path === undefined) {+ return undefined+ }+ const { config, problems } = validateConfig(await runtime.readFile(path))+ if (!config) {+ const [first] = problems+ throw new HogError(+ 'invalid_config',+ `${path} is not valid: ${first?.path ? `${first.path}: ` : ''}${first?.message ?? 'unknown problem'}`,+ 'Run `hog config check` to see every problem.'+ )+ }+ return { path, root: dirname(path), config }+}diff --git a/hog/src/core/context.ts b/hog/src/core/context.tsindex ba642ccb30d3..663794dd7206 100644--- a/hog/src/core/context.ts+++ b/hog/src/core/context.ts@@ -3,6 +3,7 @@ import { resolveCredentials, type ResolvedCredentials } from '@/posthog/credentiimport type { Mode } from './agent'import type { CommandTree, OptionSpec, OptionValues } from './command'+import { loadConfig, type LoadedConfig } from './config'import type { Prompts } from './prompts'import type { Runtime } from './runtime'@@ -37,6 +38,7 @@ export type GlobalOptions = OptionValues<typeof GLOBAL_OPTIONS>export class Context {private api?: PostHogApiprivate resolved?: ResolvedCredentials+ private loaded?: Promise<LoadedConfig | undefined>constructor(readonly runtime: Runtime,@@ -59,6 +61,13 @@ export class Context {return this.api}+ // The nearest posthog.json, or undefined when there is none. Throws `invalid_config` when it+ // doesn't match the schema.+ config(): Promise<LoadedConfig | undefined> {+ this.loaded ??= loadConfig(this.runtime)+ return this.loaded+ }+// Throws `not_authenticated` when there are none.async credentials(): Promise<ResolvedCredentials> {this.resolved ??= await resolveCredentials(this.runtime, this.globals)diff --git a/hog/src/core/manifest.ts b/hog/src/core/manifest.tsindex f05d17d94c21..e89c977b1293 100644--- a/hog/src/core/manifest.ts+++ b/hog/src/core/manifest.ts@@ -13,7 +13,7 @@ export interface ManifestEntry {name: stringdescription: stringavailable: boolean- arguments?: { name: string; description: string; required: boolean; stdin: boolean }[]+ arguments?: { name: string; description: string; required: boolean; variadic: boolean; stdin: boolean }[]options?: OptionEntry[]scopes?: readonly string[]examples?: readonly string[]@@ -48,6 +48,7 @@ export function describeCommands(tree: CommandTree, prefix = ''): ManifestEntry[name: kebabCase(argName),description: spec.description,required: spec.optional !== true,+ variadic: spec.variadic === true,stdin: spec.stdin === true,})),options: describeOptions(node.options ?? {}),@@ -59,6 +60,19 @@ export function describeCommands(tree: CommandTree, prefix = ''): ManifestEntry[})}+export function describeAliases(tree: CommandTree, prefix = ''): Record<string, string> {+ return Object.fromEntries(+ Object.entries(tree).flatMap(([name, node]) => {+ if (node.kind !== 'group') {+ return []+ }+ const path = prefix ? `${prefix} ${name}` : name+ const own = (node.aliases ?? []).map((alias) => [prefix ? `${prefix} ${alias}` : alias, path])+ return [...own, ...Object.entries(describeAliases(node.commands, path))]+ })+ )+}+export function describeGlobalOptions(): OptionEntry[] {return describeOptions(GLOBAL_OPTIONS)}diff --git a/hog/src/core/runtime.ts b/hog/src/core/runtime.tsindex 526850841a97..b576baf6f384 100644--- a/hog/src/core/runtime.ts+++ b/hog/src/core/runtime.ts@@ -1,5 +1,5 @@import { randomUUID } from 'node:crypto'-import { mkdir, readFile, rename, rm, writeFile } from 'node:fs/promises'+import { access, mkdir, readFile, rename, rm, writeFile } from 'node:fs/promises'import { homedir } from 'node:os'import { dirname } from 'node:path'@@ -21,6 +21,8 @@ export interface Runtime {now: () => numbersleep: (ms: number) => Promise<void>homeDir: () => string | undefined+ cwd: () => string+ exists: (path: string) => Promise<boolean>readFile: (path: string) => Promise<string>writePrivateFile: (path: string, contents: string) => Promise<void>removeFile: (path: string) => Promise<void>@@ -67,6 +69,12 @@ export function processRuntime(): Runtime {return undefined}},+ cwd: () => process.cwd(),+ exists: (path) =>+ access(path).then(+ () => true,+ () => false+ ),readFile: (path) => readFile(path, 'utf8'),// A rename is atomic, so a crash never leaves a half-written file. The temporary name is// random and `wx` refuses an existing path, so nobody can plant a symlink there first.diff --git a/hog/src/error-tracking/container.ts b/hog/src/error-tracking/container.tsnew file mode 100644index 000000000000..dc8de9102be0--- /dev/null+++ b/hog/src/error-tracking/container.ts@@ -0,0 +1,108 @@+import { createHash } from 'node:crypto'+import { constants, zstdCompressSync, zstdDecompressSync } from 'node:zlib'++import { HogError } from '@/core/errors'++// The symbol-data container from the posthog-symbol-data crate (0.5.2). Its bytes are what PostHog+// stores and what most content hashes cover, so every byte must match what posthog-cli writes.+export enum SymbolDataType {+ SourceAndMap = 2,+ HermesMap = 3,+ ProguardMapping = 4,+ AppleDsym = 5,+ ElfDebugInfo = 6,+}++const MAGIC = Buffer.from('posthog_error_tracking', 'latin1')+const VERSION = 2+const HEADER_LENGTH = MAGIC.length + 4 + 4 + 1+const COMPRESSION_ZSTD = 1+const ZSTD_BLOCK_SIZE = 128 * 1024++// Matches the Rust `zstd::Encoder` at level 3 with the source size pledged: one `compressStream` call+// over the whole input, then `endStream`. That differs from one-shot compression in one case: when+// the input is an exact multiple of the 128 KiB block size and larger than one block, the encoder+// marks the final data block as not last and appends an empty last block (`01 00 00`).+// `node:zlib` runs through libzstd's streaming API, which matches above the 2 MiB window, where+// `Bun.zstdCompressSync` does not.+export function zstdCompressLikeRust(raw: Uint8Array): Buffer {+ const compressed = zstdCompressSync(raw, {+ pledgedSrcSize: raw.length,+ params: { [constants.ZSTD_c_compressionLevel]: 3 },+ } as Parameters<typeof zstdCompressSync>[1])+ if (raw.length <= ZSTD_BLOCK_SIZE || raw.length % ZSTD_BLOCK_SIZE !== 0) {+ return compressed+ }+ return appendEmptyLastBlock(compressed)+}++// Walks the frame header (RFC 8878, section 3.1.1.1) and the blocks to the last one, clears its+// last-block bit, and appends an empty raw block flagged as last.+function appendEmptyLastBlock(frame: Buffer): Buffer {+ const descriptor = frame[4]!+ const contentSizeFlag = descriptor >> 6+ const singleSegment = (descriptor >> 5) & 1+ const dictionaryFlag = descriptor & 3+ let offset =+ 5 + (singleSegment ? 0 : 1) + [0, 1, 2, 4][dictionaryFlag]! + [singleSegment ? 1 : 0, 2, 4, 8][contentSizeFlag]!+ for (;;) {+ const header = frame[offset]! | (frame[offset + 1]! << 8) | (frame[offset + 2]! << 16)+ const isLast = header & 1+ const blockType = (header >> 1) & 3+ const blockSize = header >>> 3+ if (isLast) {+ const out = Buffer.alloc(frame.length + 3)+ frame.copy(out)+ out[offset] = out[offset]! & 0xfe+ out.set([1, 0, 0], frame.length)+ return out+ }+ // An RLE block stores one byte, whatever size it expands to.+ offset += 3 + (blockType === 1 ? 1 : blockSize)+ }+}++export function writeSymbolData(type: SymbolDataType, raw: Uint8Array): Buffer {+ const header = Buffer.alloc(HEADER_LENGTH)+ MAGIC.copy(header)+ header.writeUInt32LE(VERSION, MAGIC.length)+ header.writeUInt32LE(type, MAGIC.length + 4)+ header.writeUInt8(COMPRESSION_ZSTD, MAGIC.length + 8)+ return Buffer.concat([header, zstdCompressLikeRust(raw)])+}++export function readSymbolData(bytes: Uint8Array): { type: number; payload: Buffer } {+ const data = Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength)+ if (data.length < MAGIC.length + 4 || !data.subarray(0, MAGIC.length).equals(MAGIC)) {+ throw new HogError('invalid_symbol_set', "The file isn't a PostHog symbol set: the header doesn't match.")+ }+ const version = data.readUInt32LE(MAGIC.length)+ const type = data.readUInt32LE(MAGIC.length + 4)+ // Version 1 has no compression byte and is never compressed.+ if (version === 1) {+ return { type, payload: data.subarray(MAGIC.length + 8) }+ }+ if (version !== VERSION) {+ throw new HogError('invalid_symbol_set', `Unsupported symbol set version ${version}, expected 1 or 2.`)+ }+ const body = data.subarray(HEADER_LENGTH)+ return { type, payload: data[MAGIC.length + 8] === COMPRESSION_ZSTD ? zstdDecompressSync(body) : body }+}++// SHA-512 over the parts joined with nothing in between, as lowercase hex. Most uploads hash their+// whole container this way.+export function contentHash(...parts: (Uint8Array | string)[]): string {+ const hash = createHash('sha512')+ for (const part of parts) {+ hash.update(part)+ }+ return hash.digest('hex')+}++export function sourceAndMapPayload(source: Uint8Array, map: Uint8Array): Buffer {+ const sourceLength = Buffer.alloc(8)+ sourceLength.writeBigUInt64LE(BigInt(source.length))+ const mapLength = Buffer.alloc(8)+ mapLength.writeBigUInt64LE(BigInt(map.length))+ return Buffer.concat([sourceLength, source, mapLength, map])+}diff --git a/hog/src/error-tracking/discover.ts b/hog/src/error-tracking/discover.tsnew file mode 100644index 000000000000..9f63fcff6765--- /dev/null+++ b/hog/src/error-tracking/discover.ts@@ -0,0 +1,104 @@+import { readdirSync, readFileSync, statSync } from 'node:fs'+import { join, relative, resolve } from 'node:path'++import type { ArtifactKind } from '@/core/config'+import { HogError } from '@/core/errors'++import { isValidProguardMapping } from './kinds/proguard'++export interface Root {+ path: string+ kind?: ArtifactKind+ mapId?: string+}++export interface Artifact {+ kind: ArtifactKind+ path: string+ // The path as the caller sees it, relative to the working folder.+ display: string+ root: Root+}++// Each artifact type answers whether a file belongs to it. Detection is deterministic: the same+// files always give the same result, and a file only two types could claim is an error.+interface Detector {+ kind: ArtifactKind+ // While scanning a folder, only files with these extensions are opened.+ extensions: readonly string[]+ matches(path: string): boolean+}++const DETECTORS: readonly Detector[] = [+ {+ kind: 'proguard',+ extensions: ['.txt'],+ matches: (path) => isValidProguardMapping(readFileSync(path)),+ },+]++function detect(path: string, fromFolder: boolean, kind: ArtifactKind | undefined): ArtifactKind | undefined {+ const candidates = DETECTORS.filter(+ (detector) =>+ (kind === undefined || detector.kind === kind) &&+ (!fromFolder || detector.extensions.some((extension) => path.endsWith(extension)))+ )+ const matched = candidates.filter((detector) => detector.matches(path))+ if (matched.length > 1) {+ throw new HogError(+ 'ambiguous_artifact',+ `${path} looks like more than one artifact type: ${matched.map((detector) => detector.kind).join(', ')}.`,+ 'Pass --kind to say which one it is.'+ )+ }+ return matched[0]?.kind+}++function walk(folder: string, out: string[]): void {+ // Sorted, so runs on different machines visit files in the same order.+ for (const entry of readdirSync(folder, { withFileTypes: true }).sort((a, b) => (a.name < b.name ? -1 : 1))) {+ if (entry.name === 'node_modules' || entry.name === '.git') {+ continue+ }+ const path = join(folder, entry.name)+ if (entry.isDirectory()) {+ walk(path, out)+ } else if (entry.isFile()) {+ out.push(path)+ }+ }+}++export function discover(roots: readonly Root[], cwd: string): Artifact[] {+ const artifacts: Artifact[] = []+ for (const root of roots) {+ const path = resolve(cwd, root.path)+ const stat = statSync(path, { throwIfNoEntry: false })+ if (!stat) {+ throw new HogError('path_not_found', `${root.path} doesn't exist.`)+ }+ if (stat.isFile()) {+ const kind = detect(path, false, root.kind)+ if (!kind) {+ throw new HogError(+ 'unknown_artifact',+ root.kind+ ? `${root.path} isn't a valid ${root.kind} artifact.`+ : `hog couldn't tell what kind of artifact ${root.path} is.`,+ root.kind ? undefined : 'Pass --kind to say which one it is.'+ )+ }+ artifacts.push({ kind, path, display: relative(cwd, path) || path, root })+ continue+ }+ const files: string[] = []+ walk(path, files)+ for (const file of files) {+ const kind = detect(file, true, root.kind)+ if (kind) {+ artifacts.push({ kind, path: file, display: relative(cwd, file), root })+ }+ }+ }+ return artifacts+}diff --git a/hog/src/error-tracking/git.ts b/hog/src/error-tracking/git.tsnew file mode 100644index 000000000000..49742585d877--- /dev/null+++ b/hog/src/error-tracking/git.ts@@ -0,0 +1,400 @@+import { existsSync, readFileSync, realpathSync, statSync } from 'node:fs'+import { basename, dirname, isAbsolute, join } from 'node:path'++import type { Env } from '@/core/runtime'++// A port of posthog-cli's `utils/git.rs`. The repo name and commit become the default release name+// and version, and those decide the release's hash id, so they must come out exactly as in Rust.+export interface GitInfo {+ remote_url?: string+ repo_name?: string+ branch: string+ commit_id: string+}++interface RepositoryPaths {+ gitDir: string+ commonDir: string+ worktreeDir: string+}++function envValue(env: Env, name: string): string | undefined {+ const value = env[name]?.trim()+ return value ? value : undefined+}++function fromGitHub(env: Env): GitInfo | undefined {+ if (!envValue(env, 'GITHUB_ACTIONS')) {+ return undefined+ }+ const branch = envValue(env, 'GITHUB_REF_NAME')+ const commit = envValue(env, 'GITHUB_SHA')+ const repository = envValue(env, 'GITHUB_REPOSITORY')+ const server = envValue(env, 'GITHUB_SERVER_URL')+ if (!branch || !commit || !repository || !server) {+ return undefined+ }+ return {+ remote_url: `${server}/${repository}.git`,+ repo_name: repository.split('/').at(-1),+ branch,+ commit_id: commit,+ }+}++const VERCEL_PROVIDERS: Record<string, string> = {+ github: 'https://github.com',+ gitlab: 'https://gitlab.com',+ bitbucket: 'https://bitbucket.org',+}++function fromVercel(env: Env): GitInfo | undefined {+ if (!envValue(env, 'VERCEL')) {+ return undefined+ }+ const branch = envValue(env, 'VERCEL_GIT_COMMIT_REF')+ const commit = envValue(env, 'VERCEL_GIT_COMMIT_SHA')+ const slug = envValue(env, 'VERCEL_GIT_REPO_SLUG')+ if (!branch || !commit || !slug) {+ return undefined+ }+ const provider = VERCEL_PROVIDERS[envValue(env, 'VERCEL_GIT_PROVIDER') ?? '']+ const owner = envValue(env, 'VERCEL_GIT_REPO_OWNER')+ const info: GitInfo = { repo_name: slug, branch, commit_id: commit }+ if (provider && owner) {+ info.remote_url = `${provider}/${owner}/${slug}.git`+ }+ return info+}++function isDirectory(path: string): boolean {+ return statSync(path, { throwIfNoEntry: false })?.isDirectory() ?? false+}++function isFile(path: string): boolean {+ return statSync(path, { throwIfNoEntry: false })?.isFile() ?? false+}++function readText(path: string): string | undefined {+ try {+ return readFileSync(path, 'utf8')+ } catch {+ return undefined+ }+}++function canonical(path: string): string {+ try {+ return realpathSync(path)+ } catch {+ return path+ }+}++function findRepository(start: string): RepositoryPaths | undefined {+ let current = start+ for (;;) {+ const gitPath = join(current, '.git')+ if (isDirectory(gitPath)) {+ const gitDir = canonical(gitPath)+ return { gitDir, commonDir: gitDir, worktreeDir: current }+ }+ if (isFile(gitPath)) {+ // A worktree or submodule: `.git` is a file that points at the real git dir.+ const pointer = readText(gitPath)?.trim()+ if (!pointer?.startsWith('gitdir:')) {+ return undefined+ }+ const target = pointer.slice('gitdir:'.length).trim()+ const gitDir = canonical(isAbsolute(target) ? target : join(dirname(gitPath), target))+ const commondir = readText(join(gitDir, 'commondir'))?.trim()+ const commonDir =+ commondir === undefined+ ? gitDir+ : canonical(isAbsolute(commondir) ? commondir : join(gitDir, commondir))+ return { gitDir, commonDir, worktreeDir: current }+ }+ const parent = dirname(current)+ if (parent === current) {+ return undefined+ }+ current = parent+ }+}++function configPaths({ gitDir, commonDir }: RepositoryPaths): string[] {+ const paths = [join(gitDir, 'config.worktree')]+ if (commonDir !== gitDir) {+ paths.push(join(commonDir, 'config'))+ }+ paths.push(join(gitDir, 'config'))+ return paths+}++// Index of the `]` that closes a section header. A quoted subsection can hold its own `]`.+function sectionHeaderEnd(line: string): number | undefined {+ let inQuotes = false+ let escaped = false+ for (let index = 0; index < line.length; index++) {+ const char = line[index]+ if (escaped) {+ escaped = false+ } else if (char === '\\') {+ escaped = true+ } else if (char === '"') {+ inQuotes = !inQuotes+ } else if (char === ']' && !inQuotes) {+ return index+ }+ }+ return undefined+}++function stripComment(line: string): string {+ let inQuotes = false+ let escaped = false+ for (let index = 0; index < line.length; index++) {+ const char = line[index]+ if (escaped) {+ escaped = false+ } else if (char === '\\') {+ escaped = true+ } else if (char === '"') {+ inQuotes = !inQuotes+ } else if ((char === '#' || char === ';') && !inQuotes) {+ return line.slice(0, index).trimEnd()+ }+ }+ return line+}++// Git keeps the character after `\` in a subsection name and drops the backslash.+function unescapeSubsection(name: string): string {+ let out = ''+ for (let index = 0; index < name.length; index++) {+ if (name[index] === '\\') {+ index+++ out += name[index] ?? ''+ } else {+ out += name[index]+ }+ }+ return out+}++function remoteName(header: string): string | undefined {+ const trimmed = header.trim()+ const quote = trimmed.indexOf('"')+ if (quote === -1 || trimmed.slice(0, quote).trim().toLowerCase() !== 'remote') {+ return undefined+ }+ const subsection = trimmed.slice(quote + 1)+ if (!subsection.endsWith('"')) {+ return undefined+ }+ const name = unescapeSubsection(subsection.slice(0, -1))+ return name || undefined+}++function unescapeValue(value: string): string {+ let out = ''+ for (let index = 0; index < value.length; index++) {+ const char = value[index]+ if (char === '"') {+ continue+ }+ if (char === '\\') {+ const next = value[index + 1]+ if (next === '"' || next === '\\') {+ out += next+ index+++ } else if (next === undefined) {+ out += '\\'+ } else {+ out += `\\${next}`+ index+++ }+ continue+ }+ out += char+ }+ return out+}++function parseRemoteUrls(config: string): [string, string][] {+ const remotes: [string, string][] = []+ let current: string | undefined+ // Rust's `str::lines` splits on `\n` and drops one trailing `\r` per line.+ for (const rawLine of config.split('\n')) {+ let line = stripComment(rawLine.replace(/\r$/, '').trim())+ if (line.startsWith('[')) {+ const end = sectionHeaderEnd(line)+ if (end === undefined) {+ current = undefined+ continue+ }+ current = remoteName(line.slice(1, end))+ line = line.slice(end + 1).trim()+ }+ if (current === undefined) {+ continue+ }+ const equals = line.indexOf('=')+ if (equals === -1 || line.slice(0, equals).trim().toLowerCase() !== 'url') {+ continue+ }+ const url = unescapeValue(line.slice(equals + 1).trim())+ if (url) {+ remotes.push([current, url])+ }+ }+ return remotes+}++function findRemoteUrl(paths: RepositoryPaths): string | undefined {+ const remotes: [string, string][] = []+ for (const path of configPaths(paths)) {+ const content = readText(path)+ if (content === undefined) {+ continue+ }+ for (const [name, url] of parseRemoteUrls(content)) {+ if (!remotes.some(([known]) => known === name)) {+ remotes.push([name, url])+ }+ }+ }+ return (remotes.find(([name]) => name === 'origin') ?? remotes[0])?.[1]+}++// Drops anything that can carry a credential (userinfo, query, fragment) before the URL is stored,+// and refuses URLs whose `@` sits where no parser can tell a token from a path.+export function stripCredentials(url: string): string | undefined {+ const cut = url.search(/[?#]/)+ const trimmed = cut === -1 ? url : url.slice(0, cut)+ if (url.includes('@') && !trimmed.includes('@')) {+ return undefined+ }+ if (!trimmed.includes('://')) {+ const colon = trimmed.indexOf(':')+ const path = colon === -1 ? '' : trimmed.slice(colon + 1)+ return path.includes('@') ? undefined : trimmed+ }+ let parsed: URL+ try {+ parsed = new URL(trimmed)+ } catch {+ return trimmed.includes('@') ? undefined : trimmed+ }+ if (parsed.pathname.includes('@')) {+ return undefined+ }+ if (parsed.username === '' && parsed.password === '') {+ return trimmed+ }+ parsed.username = ''+ parsed.password = ''+ return parsed.toString()+}++function remoteUrl(paths: RepositoryPaths): string | undefined {+ const url = findRemoteUrl(paths)+ const sanitized = url === undefined ? undefined : stripCredentials(url)+ if (sanitized === undefined) {+ return undefined+ }+ return sanitized.endsWith('.git') ? sanitized : `${sanitized}.git`+}++function repoName(paths: RepositoryPaths): string | undefined {+ const url = findRemoteUrl(paths)+ const sanitized = url === undefined ? undefined : stripCredentials(url)+ if (sanitized !== undefined) {+ // Rust's `trim_end_matches(".git")` removes every trailing `.git`, so `x.git.git` becomes `x`.+ const name = (sanitized.split('/').at(-1) ?? '').replace(/(\.git)+$/, '')+ if (name) {+ return name+ }+ }+ return basename(paths.worktreeDir) || undefined+}++export class GitError extends Error {}++function branchName(gitDir: string): string {+ const head = readText(join(gitDir, 'HEAD'))+ if (head === undefined) {+ throw new GitError(`Failed to determine current branch: failed to open HEAD file at ${join(gitDir, 'HEAD')}`)+ }+ if (head.startsWith('ref: refs/heads/')) {+ return head.replace(/^(ref: refs\/heads\/)+/, '').trim()+ }+ const trimmed = head.trim()+ if (trimmed.length === 40 || trimmed.length === 64) {+ return 'HEAD-detached'+ }+ throw new GitError('Failed to determine current branch: unrecognized HEAD format')+}++function commitSha(paths: RepositoryPaths, branch: string): string {+ if (branch === 'HEAD-detached') {+ return (readText(join(paths.gitDir, 'HEAD')) ?? '').trim()+ }+ const loose = [join(paths.gitDir, 'refs/heads', branch)]+ if (paths.commonDir !== paths.gitDir) {+ loose.push(join(paths.commonDir, 'refs/heads', branch))+ }+ for (const path of loose) {+ if (existsSync(path)) {+ const sha = readText(path)+ if (sha === undefined) {+ throw new GitError(`Failed to determine commit sha: failed to read branch reference at ${path}`)+ }+ return sha.trim()+ }+ }+ // Clones and `git gc` pack loose refs into packed-refs.+ const packed = [join(paths.gitDir, 'packed-refs')]+ if (paths.commonDir !== paths.gitDir) {+ packed.push(join(paths.commonDir, 'packed-refs'))+ }+ const refName = `refs/heads/${branch}`+ for (const path of packed) {+ for (const rawLine of (readText(path) ?? '').split('\n')) {+ const line = rawLine.trim()+ if (!line || line.startsWith('#') || line.startsWith('^')) {+ continue+ }+ const [sha, ref] = line.split(/\s+/)+ if (sha && ref === refName) {+ return sha+ }+ }+ }+ throw new GitError('Failed to determine commit sha: could not determine commit ID')+}++// Git info from CI variables (GitHub Actions, Vercel), else from the repository that contains+// `start`. Undefined when there is neither. Throws a GitError when the repository can't be read.+export function gitInfo(env: Env, start: string): GitInfo | undefined {+ const fromEnv = fromGitHub(env) ?? fromVercel(env)+ if (fromEnv) {+ return fromEnv+ }+ const paths = findRepository(start)+ if (!paths) {+ return undefined+ }+ const info: GitInfo = { branch: '', commit_id: '' }+ const remote = remoteUrl(paths)+ if (remote !== undefined) {+ info.remote_url = remote+ }+ const name = repoName(paths)+ if (name !== undefined) {+ info.repo_name = name+ }+ info.branch = branchName(paths.gitDir)+ info.commit_id = commitSha(paths, info.branch)+ return info+}diff --git a/hog/src/error-tracking/json.ts b/hog/src/error-tracking/json.tsnew file mode 100644index 000000000000..7aad13f85f85--- /dev/null+++ b/hog/src/error-tracking/json.ts@@ -0,0 +1,448 @@+// A JSON reader and writer that produce the same bytes as serde_json 1.0.145 with default features,+// which posthog-cli uses to read and rewrite sourcemaps. The bytes feed uploads and content hashes,+// so `JSON.parse` and `JSON.stringify` are not enough: they reorder integer-like keys, round large+// integers, print `1.0` as `1`, and accept lone surrogates and `1e400`, which serde rejects.++export type JsonNumber = { kind: 'u' | 'i'; value: bigint } | { kind: 'f'; value: number }++// serde_json without `preserve_order` stores objects in a BTreeMap, so output keys are sorted by+// their UTF-8 bytes. A Map keeps the values; the writer sorts.+export class JsonObject {+ readonly entries = new Map<string, JsonValue>()+}++export type JsonValue = null | boolean | string | JsonNumber | JsonValue[] | JsonObject++export function isJsonNumber(value: JsonValue | undefined): value is JsonNumber {+ return value !== null && typeof value === 'object' && !Array.isArray(value) && !(value instanceof JsonObject)+}++const POW10 = Array.from({ length: 309 }, (_, index) => Number(`1e${index}`))+const U64_MAX = (1n << 64n) - 1n+const LONE_SURROGATE = /[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/+// serde_json's recursion limit: nesting deeper than this is an error.+const MAX_DEPTH = 128++export class JsonError extends Error {}++const strictUtf8 = new TextDecoder('utf-8', { fatal: true, ignoreBOM: true })++// serde_json::from_slice rejects invalid UTF-8 and treats a BOM as an unexpected character.+export function decodeUtf8(bytes: Uint8Array): string {+ return strictUtf8.decode(bytes)+}++export class JsonParser {+ index = 0+ private depth = 0++ constructor(readonly text: string) {}++ fail(message: string): never {+ throw new JsonError(`${message} at character ${this.index}`)+ }++ skipWhitespace(): void {+ const text = this.text+ for (;;) {+ const code = text.charCodeAt(this.index)+ if (code !== 32 && code !== 10 && code !== 13 && code !== 9) {+ return+ }+ this.index+++ }+ }++ value(): JsonValue {+ this.skipWhitespace()+ const char = this.text[this.index]+ switch (char) {+ case '{':+ return this.object()+ case '[':+ return this.array()+ case '"':+ return this.string()+ case 't':+ return this.literal('true', true)+ case 'f':+ return this.literal('false', false)+ case 'n':+ return this.literal('null', null)+ case '-':+ this.index+++ return this.number(false)+ default:+ if (char !== undefined && char >= '0' && char <= '9') {+ return this.number(true)+ }+ return this.fail('expected value')+ }+ }++ enter(): void {+ if (++this.depth >= MAX_DEPTH) {+ this.fail('recursion limit exceeded')+ }+ }++ leave(): void {+ this.depth--+ }++ private literal(word: string, value: JsonValue): JsonValue {+ if (!this.text.startsWith(word, this.index)) {+ this.fail('expected ident')+ }+ this.index += word.length+ return value+ }++ private object(): JsonObject {+ this.enter()+ this.index+++ const object = new JsonObject()+ this.skipWhitespace()+ if (this.text[this.index] === '}') {+ this.index+++ this.leave()+ return object+ }+ for (;;) {+ this.skipWhitespace()+ if (this.text[this.index] !== '"') {+ this.fail('key must be a string')+ }+ const key = this.string()+ this.skipWhitespace()+ if (this.text[this.index] !== ':') {+ this.fail('expected `:`')+ }+ this.index+++ // A repeated key keeps the last value, as in serde_json's Value.+ object.entries.set(key, this.value())+ this.skipWhitespace()+ const next = this.text[this.index++]+ if (next === '}') {+ break+ }+ if (next !== ',') {+ this.fail('expected `,` or `}`')+ }+ }+ this.leave()+ return object+ }++ private array(): JsonValue[] {+ this.enter()+ this.index+++ const array: JsonValue[] = []+ this.skipWhitespace()+ if (this.text[this.index] === ']') {+ this.index+++ this.leave()+ return array+ }+ for (;;) {+ array.push(this.value())+ this.skipWhitespace()+ const next = this.text[this.index++]+ if (next === ']') {+ break+ }+ if (next !== ',') {+ this.fail('expected `,` or `]`')+ }+ }+ this.leave()+ return array+ }++ string(): string {+ const text = this.text+ const start = this.index+ let end = start + 1+ let escaped = false+ for (;;) {+ const code = text.charCodeAt(end)+ if (Number.isNaN(code)) {+ this.fail('EOF while parsing a string')+ }+ if (code === 34) {+ break+ }+ if (code === 92) {+ escaped = true+ end += 2+ continue+ }+ if (code < 0x20) {+ this.fail('control character found while parsing a string')+ }+ end+++ }+ this.index = end + 1+ if (!escaped) {+ return text.slice(start + 1, end)+ }+ const decoded = JSON.parse(text.slice(start, end + 1)) as string+ if (LONE_SURROGATE.test(decoded)) {+ this.fail('lone leading surrogate in hex escape')+ }+ return decoded+ }++ private digit(): number {+ const code = this.text.charCodeAt(this.index)+ return code >= 48 && code <= 57 ? code - 48 : -1+ }++ // serde_json's number parser without `float_roundtrip`: the digits accumulate into a u64+ // significand, then one multiply or divide by a power of ten. It is not always correctly rounded,+ // which is why `Number(text)` can disagree with it.+ private number(positive: boolean): JsonNumber {+ let digit = this.digit()+ if (digit < 0) {+ this.fail('invalid number')+ }+ this.index+++ let significand = BigInt(digit)+ if (digit === 0) {+ if (this.digit() >= 0) {+ this.fail('invalid number')+ }+ return this.afterInteger(positive, 0n)+ }+ for (;;) {+ digit = this.digit()+ if (digit < 0) {+ return this.afterInteger(positive, significand)+ }+ const next = significand * 10n + BigInt(digit)+ if (next > U64_MAX) {+ return { kind: 'f', value: this.longInteger(positive, significand) }+ }+ this.index+++ significand = next+ }+ }++ private longInteger(positive: boolean, significand: bigint): number {+ let exponent = 0+ while (this.digit() >= 0) {+ this.index+++ exponent+++ }+ const char = this.text[this.index]+ if (char === '.') {+ return this.decimal(positive, significand, exponent)+ }+ if (char === 'e' || char === 'E') {+ return this.exponent(positive, significand, exponent)+ }+ return this.fromParts(positive, significand, exponent)+ }++ private afterInteger(positive: boolean, significand: bigint): JsonNumber {+ const char = this.text[this.index]+ if (char === '.') {+ return { kind: 'f', value: this.decimal(positive, significand, 0) }+ }+ if (char === 'e' || char === 'E') {+ return { kind: 'f', value: this.exponent(positive, significand, 0) }+ }+ if (positive) {+ return { kind: 'u', value: significand }+ }+ // serde_json keeps a negative integer when it fits i64, and makes -0 a float.+ const negated = BigInt.asIntN(64, -BigInt.asIntN(64, significand))+ if (negated >= 0n) {+ return { kind: 'f', value: -Number(significand) }+ }+ return { kind: 'i', value: negated }+ }++ private decimal(positive: boolean, significand: bigint, exponentBefore: number): number {+ this.index+++ let after = 0+ let digit+ while ((digit = this.digit()) >= 0) {+ const next = significand * 10n + BigInt(digit)+ if (next > U64_MAX) {+ while (this.digit() >= 0) {+ this.index+++ }+ const char = this.text[this.index]+ if (char === 'e' || char === 'E') {+ return this.exponent(positive, significand, exponentBefore + after)+ }+ return this.fromParts(positive, significand, exponentBefore + after)+ }+ this.index+++ significand = next+ after--+ }+ if (after === 0) {+ this.fail('invalid number')+ }+ const char = this.text[this.index]+ if (char === 'e' || char === 'E') {+ return this.exponent(positive, significand, exponentBefore + after)+ }+ return this.fromParts(positive, significand, exponentBefore + after)+ }++ private exponent(positive: boolean, significand: bigint, start: number): number {+ this.index+++ let positiveExponent = true+ if (this.text[this.index] === '+') {+ this.index+++ } else if (this.text[this.index] === '-') {+ this.index+++ positiveExponent = false+ }+ let digit = this.digit()+ if (digit < 0) {+ this.fail('invalid number')+ }+ this.index+++ let exponent = digit+ while ((digit = this.digit()) >= 0) {+ this.index+++ if (exponent * 10 + digit > 2147483647) {+ if (significand !== 0n && positiveExponent) {+ this.fail('number out of range')+ }+ while (this.digit() >= 0) {+ this.index+++ }+ return positive ? 0 : -0+ }+ exponent = exponent * 10 + digit+ }+ const total = positiveExponent ? start + exponent : start - exponent+ return this.fromParts(positive, significand, Math.max(-2147483648, Math.min(2147483647, total)))+ }++ private fromParts(positive: boolean, significand: bigint, exponent: number): number {+ let value = Number(significand)+ for (;;) {+ const magnitude = Math.abs(exponent)+ if (magnitude < POW10.length) {+ if (exponent >= 0) {+ value *= POW10[magnitude]!+ if (!Number.isFinite(value)) {+ this.fail('number out of range')+ }+ } else {+ value /= POW10[magnitude]!+ }+ break+ }+ if (value === 0) {+ break+ }+ if (exponent >= 0) {+ this.fail('number out of range')+ }+ value /= 1e308+ exponent += 308+ }+ return positive ? value : -value+ }++ end(): void {+ this.skipWhitespace()+ if (this.index !== this.text.length) {+ this.fail('trailing characters')+ }+ }+}++export function parseJson(text: string): JsonValue {+ const parser = new JsonParser(text)+ const value = parser.value()+ parser.end()+ return value+}++// ryu's `format_finite` layout over JavaScript's shortest round-trip digits.+export function formatFloat(value: number): string {+ const sign = value < 0 || Object.is(value, -0) ? '-' : ''+ if (value === 0) {+ return `${sign}0.0`+ }+ const [mantissa = '', exponentText = '0'] = Math.abs(value).toExponential().split('e')+ const digits = mantissa.replace('.', '')+ const length = digits.length+ const kk = Number(exponentText) + 1+ const k = kk - length+ let out: string+ if (k >= 0 && kk <= 16) {+ out = `${digits}${'0'.repeat(k)}.0`+ } else if (kk > 0 && kk <= 16) {+ out = `${digits.slice(0, kk)}.${digits.slice(kk)}`+ } else if (kk > -5 && kk <= 0) {+ out = `0.${'0'.repeat(-kk)}${digits}`+ } else if (length === 1) {+ out = `${digits}e${kk - 1}`+ } else {+ out = `${digits[0]}.${digits.slice(1)}e${kk - 1}`+ }+ return sign + out+}++export function compareUtf8(a: string, b: string): number {+ return Buffer.compare(Buffer.from(a, 'utf8'), Buffer.from(b, 'utf8'))+}++// serde_json escapes the same characters as JSON.stringify for strings without lone surrogates,+// which the parser already rejects.+export function writeString(value: string): string {+ return JSON.stringify(value)+}++export function writeJson(value: JsonValue, parts: string[] = []): string[] {+ if (value === null) {+ parts.push('null')+ } else if (value === true) {+ parts.push('true')+ } else if (value === false) {+ parts.push('false')+ } else if (typeof value === 'string') {+ parts.push(writeString(value))+ } else if (Array.isArray(value)) {+ parts.push('[')+ value.forEach((item, index) => {+ if (index > 0) {+ parts.push(',')+ }+ writeJson(item, parts)+ })+ parts.push(']')+ } else if (value instanceof JsonObject) {+ writeEntries([...value.entries], parts)+ } else {+ parts.push(value.kind === 'f' ? formatFloat(value.value) : value.value.toString())+ }+ return parts+}++export function writeEntries(entries: [string, JsonValue][], parts: string[]): void {+ parts.push('{')+ entries+ .sort((a, b) => compareUtf8(a[0], b[0]))+ .forEach(([key, item], index) => {+ if (index > 0) {+ parts.push(',')+ }+ parts.push(writeString(key), ':')+ writeJson(item, parts)+ })+ parts.push('}')+}++export function stringifyJson(value: JsonValue): string {+ return writeJson(value).join('')+}diff --git a/hog/src/error-tracking/kinds/proguard.ts b/hog/src/error-tracking/kinds/proguard.tsnew file mode 100644index 000000000000..8540c7e208af--- /dev/null+++ b/hog/src/error-tracking/kinds/proguard.ts@@ -0,0 +1,213 @@+import { readFileSync } from 'node:fs'++import { HogError } from '@/core/errors'++import { SymbolDataType, writeSymbolData } from '../container'+import { decodeUtf8 } from '../json'++// ProGuard and R8 mapping files. A port of the proguard 5.7.0 crate's `is_valid`, which posthog-cli+// uses to accept or reject a mapping: among the first 50 records, a field or method must follow a+// class. It works on bytes, like the crate, because its quirks are byte-level.++const NEWLINE = (byte: number | undefined): boolean => byte === 13 || byte === 10+const strictUtf8 = new TextDecoder('utf-8', { fatal: true })++class Reject extends Error {}++function isUtf8(bytes: Uint8Array): boolean {+ try {+ strictUtf8.decode(bytes)+ return true+ } catch {+ return false+ }+}++function skipNewlines(bytes: Uint8Array, at: number): number {+ while (at < bytes.length && NEWLINE(bytes[at])) {+ at+++ }+ return at+}++function startsWith(bytes: Uint8Array, at: number, prefix: string): boolean {+ for (let index = 0; index < prefix.length; index++) {+ if (bytes[at + index] !== prefix.charCodeAt(index)) {+ return false+ }+ }+ return true+}++function expect(bytes: Uint8Array, at: number, prefix: string): number {+ if (!startsWith(bytes, at, prefix)) {+ throw new Reject()+ }+ return at + prefix.length+}++// `parse_until`: everything up to the first byte matching `stop`, which must be valid UTF-8.+function until(bytes: Uint8Array, at: number, stop: (byte: number) => boolean): number {+ let end = at+ while (end < bytes.length && !stop(bytes[end]!)) {+ end+++ }+ if (!isUtf8(bytes.subarray(at, end))) {+ throw new Reject()+ }+ return end+}++// `parse_until_no_newline`: like `until`, but stopping at a newline is an error.+function untilNoNewline(bytes: Uint8Array, at: number, stop: (byte: number) => boolean): number {+ const end = until(bytes, at, (byte) => NEWLINE(byte) || stop(byte))+ if (end < bytes.length && NEWLINE(bytes[end])) {+ throw new Reject()+ }+ return end+}++// Latin-1 bytes Rust's `char::is_numeric` accepts: ASCII digits plus ², ³, ¹, ¼, ½ and ¾.+const NUMERIC_BYTES = new Set([0xb2, 0xb3, 0xb9, 0xbc, 0xbd, 0xbe])+const isNumericByte = (byte: number): boolean => (byte >= 48 && byte <= 57) || NUMERIC_BYTES.has(byte)++// `parse_usize`: the numeric run must be valid UTF-8 and parse as a non-empty usize.+function parseNumber(bytes: Uint8Array, at: number): number {+ let end = at+ while (end < bytes.length && isNumericByte(bytes[end]!)) {+ end+++ }+ const slice = bytes.subarray(at, end)+ if (slice.length === 0 || !isUtf8(slice) || !/^\d+$/.test(Buffer.from(slice).toString('latin1'))) {+ throw new Reject()+ }+ if (BigInt(Buffer.from(slice).toString('latin1')) > 0xffffffffffffffffn) {+ throw new Reject()+ }+ return end+}++type RecordKind = 'header' | 'class' | 'member' | 'error'++function headerRecord(bytes: Uint8Array, at: number): number {+ if (bytes[at] === 0x7b) {+ // An R8 JSON header: whether it parses doesn't change `is_valid`, only the line it takes.+ return skipNewlines(+ bytes,+ until(bytes, at, (byte) => NEWLINE(byte))+ )+ }+ let end = until(bytes, at, (byte) => byte === 0x3a || NEWLINE(byte))+ if (bytes[end] === 0x3a) {+ end = until(bytes, end + 1, (byte) => NEWLINE(byte))+ }+ return skipNewlines(bytes, end)+}++function memberRecord(bytes: Uint8Array, at: number): number {+ let index = expect(bytes, at, ' ')+ let hasStart = false+ try {+ index = parseNumber(bytes, index)+ hasStart = true+ } catch {}+ if (hasStart) {+ index = expect(bytes, index, ':')+ index = parseNumber(bytes, index)+ index = expect(bytes, index, ':')+ }+ index = untilNoNewline(bytes, index, (byte) => byte === 0x20)+ index = expect(bytes, index, ' ')+ index = untilNoNewline(bytes, index, (byte) => byte === 0x20 || byte === 0x28)+ let isMethod = false+ if (bytes[index] === 0x28) {+ isMethod = true+ index = untilNoNewline(bytes, index + 1, (byte) => byte === 0x29)+ index = expect(bytes, index, ')')+ }+ if (isMethod && bytes[index] === 0x3a) {+ index = parseNumber(bytes, index + 1)+ if (bytes[index] === 0x3a) {+ index = parseNumber(bytes, index + 1)+ }+ }+ index = expect(bytes, index, ' -> ')+ index = until(bytes, index, (byte) => NEWLINE(byte))+ return skipNewlines(bytes, index)+}++function classRecord(bytes: Uint8Array, at: number): number {+ let index = untilNoNewline(bytes, at, (byte) => byte === 0x20)+ index = expect(bytes, index, ' -> ')+ index = untilNoNewline(bytes, index, (byte) => byte === 0x3a)+ index = expect(bytes, index, ':')+ return skipNewlines(bytes, index)+}++function nextRecord(bytes: Uint8Array, start: number): [RecordKind, number] {+ const at = skipNewlines(bytes, start)+ let trimmed = at+ while (trimmed < bytes.length && [0x20, 0x09, 0x0a, 0x0c, 0x0d].includes(bytes[trimmed]!)) {+ trimmed+++ }+ try {+ if (bytes[trimmed] === 0x23) {+ let afterHash = trimmed + 1+ while (afterHash < bytes.length && [0x20, 0x09, 0x0a, 0x0c, 0x0d].includes(bytes[afterHash]!)) {+ afterHash+++ }+ return ['header', headerRecord(bytes, afterHash)]+ }+ if (startsWith(bytes, at, ' ')) {+ return ['member', memberRecord(bytes, at)]+ }+ return ['class', classRecord(bytes, at)]+ } catch (error) {+ if (!(error instanceof Reject)) {+ throw error+ }+ // A bad record consumes its line, newline included.+ let end = at+ while (end < bytes.length && !NEWLINE(bytes[end])) {+ end+++ }+ return ['error', Math.min(end + 1, bytes.length)]+ }+}++export function isValidProguardMapping(bytes: Uint8Array): boolean {+ let hasClass = false+ let at = 0+ for (let count = 0; count < 50 && at < bytes.length; count++) {+ const [kind, next] = nextRecord(bytes, at)+ at = next+ if (kind === 'class') {+ hasClass = true+ } else if (kind === 'member' && hasClass) {+ return true+ }+ }+ return false+}++// Reads and validates a mapping. The payload is the file's raw bytes: a BOM or CRLF stays, because+// posthog-cli uploads the bytes as they are and hashes them that way.+export function proguardContainer(path: string, displayPath: string): Buffer {+ const bytes = readFileSync(path)+ try {+ decodeUtf8(bytes)+ } catch {+ throw new HogError(+ 'invalid_proguard_mapping',+ `${displayPath} isn't valid UTF-8, so it can't be a ProGuard mapping.`+ )+ }+ if (!isValidProguardMapping(bytes)) {+ throw new HogError(+ 'invalid_proguard_mapping',+ `${displayPath} is not a valid ProGuard mapping file.`,+ 'Pass the mapping.txt that the Android build writes, usually under app/build/outputs/mapping/.'+ )+ }+ return writeSymbolData(SymbolDataType.ProguardMapping, bytes)+}diff --git a/hog/src/error-tracking/release.ts b/hog/src/error-tracking/release.tsnew file mode 100644index 000000000000..3eeef728c65a--- /dev/null+++ b/hog/src/error-tracking/release.ts@@ -0,0 +1,106 @@+import { HogError } from '@/core/errors'++import { contentHash } from './container'+import type { GitInfo } from './git'+import { ApiFailure, type SymbolSetClient } from './upload'++export interface Release {+ id: string+ hash_id: string+ version: string+ project: string+}++export interface ReleaseFields {+ name?: string+ version?: string+ build?: string+}++// posthog-cli's `pack_version`: `version+build`, or whichever of the two is set.+export function packVersion(version: string | undefined, build: string | undefined): string | undefined {+ if (version !== undefined && build !== undefined) {+ return `${version}+${build}`+ }+ return version ?? build+}++// The release's identity on the server. Symbolication recomputes it for mobile releases, so it must+// stay exactly SHA-512 of the name followed by the version, with nothing between them.+export function releaseHashId(name: string, version: string): string {+ return contentHash(name, version)+}++export function resolveRelease(fields: ReleaseFields, git: GitInfo | undefined): { name?: string; version?: string } {+ return {+ name: fields.name ?? git?.repo_name,+ version: packVersion(fields.version, fields.build) ?? git?.commit_id,+ }+}++// serde_json turns the git info into a map with sorted keys before it is sent.+function gitMetadata(git: GitInfo): Record<string, string> {+ return Object.fromEntries(+ Object.entries(git)+ .filter(([, value]) => value !== undefined)+ .sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))+ )+}++async function lookup(client: SymbolSetClient, hashId: string): Promise<Release | undefined> {+ try {+ return (await client.api('GET', `error_tracking/releases/hash/${hashId}`)) as Release+ } catch (error) {+ if (error instanceof ApiFailure && error.status === 404) {+ return undefined+ }+ throw new HogError('release_lookup_failed', `hog couldn't look up the release: ${(error as Error).message}`)+ }+}++// Finds the release by its hash id, or creates it. Two builds racing to create the same release is+// fine: the loser looks it up again.+export async function fetchOrCreateRelease(+ client: SymbolSetClient,+ name: string,+ version: string,+ metadata: { git?: GitInfo; dsym_info?: Record<string, string | null> } = {}+): Promise<Release> {+ const hashId = releaseHashId(name, version)+ const existing = await lookup(client, hashId)+ if (existing) {+ return { ...existing, id: existing.id.toLowerCase() }+ }+ const body: Record<string, unknown> = {}+ const meta: Record<string, unknown> = {}+ if (metadata.git) {+ meta.git = gitMetadata(metadata.git)+ }+ if (metadata.dsym_info) {+ meta.dsym_info = metadata.dsym_info+ }+ if (Object.keys(meta).length > 0) {+ body.metadata = meta+ }+ Object.assign(body, { hash_id: hashId, version, project: name })+ try {+ const created = (await client.api('POST', 'error_tracking/releases', body)) as Release+ return { ...created, id: created.id.toLowerCase() }+ } catch (error) {+ if (error instanceof ApiFailure && isStructuredCode(error.body, 'release_hash_in_use')) {+ const raced = await lookup(client, hashId)+ if (raced) {+ return { ...raced, id: raced.id.toLowerCase() }+ }+ }+ throw new HogError('release_create_failed', `hog couldn't create the release: ${(error as Error).message}`)+ }+}++function isStructuredCode(body: string, code: string): boolean {+ try {+ return (JSON.parse(body) as { code?: unknown }).code === code+ } catch {+ return false+ }+}diff --git a/hog/src/error-tracking/upload.ts b/hog/src/error-tracking/upload.tsnew file mode 100644index 000000000000..5c8bd8b3a72d--- /dev/null+++ b/hog/src/error-tracking/upload.ts@@ -0,0 +1,453 @@+import { HogError } from '@/core/errors'+import type { Runtime } from '@/core/runtime'+import { USER_AGENT } from '@/posthog/api'+import type { Credentials } from '@/posthog/credentials'++import { contentHash } from './container'++// The symbol set upload protocol of posthog-cli (`api/symbol_sets.rs`). Bodies, endpoints, retry+// counts and the release-mismatch fallback match it, so PostHog sees the same requests from either+// CLI. Only the user agent differs.++export interface SymbolSetUpload {+ chunkId: string+ releaseId: string | null+ data: Uint8Array+ // Set when the hash covers something other than the whole container, like event-mode sourcemaps.+ contentHash?: string+}++export type UploadStatus = 'uploaded' | 'already_present' | 'too_large'++export interface UploadOptions {+ batchSize: number+ force: boolean+ skipOnConflict: boolean+ concurrency?: number+}++export interface UploadOutcome {+ status: Map<string, UploadStatus>+ contentHashes: Map<string, string>+}++const MAX_FILE_SIZE = 100 * 1024 * 1024+const CHECK_BATCH_SIZE = 1000+const REQUEST_TIMEOUT_MS = 30_000+// A symbol set can be 100 MB. Its deadline grows with its size, so only a link slower than this fails.+const MIN_TRANSFER_BYTES_PER_SECOND = 50_000++function transferTimeout(bytes: number): number {+ return REQUEST_TIMEOUT_MS + Math.ceil((bytes / MIN_TRANSFER_BYTES_PER_SECOND) * 1000)+}+const RATE_LIMIT_PER_MINUTE = 480++class ApiFailure extends Error {+ constructor(+ readonly status: number | undefined,+ readonly body: string,+ readonly url: string+ ) {+ super(+ status === undefined+ ? `Request to ${url} failed: ${body}`+ : `PostHog answered ${status} for ${url}: ${body}`+ )+ }++ // posthog-cli matches error codes in the parsed body, or anywhere in the raw text as a fallback.+ hasCode(code: string): boolean {+ try {+ if ((JSON.parse(this.body) as { code?: unknown }).code === code) {+ return true+ }+ } catch {}+ return this.body.includes(code)+ }+}++class ReleaseIdMismatch extends Error {}++// A sliding window of request times over the last minute, like posthog-cli's throttler.+class Throttle {+ private readonly times: number[] = []++ constructor(+ private readonly runtime: Runtime,+ private readonly perMinute: number+ ) {}++ async wait(): Promise<void> {+ if (this.times.length >= this.perMinute) {+ const oldest = this.times.shift()!+ const delay = oldest + 60_000 - this.runtime.now()+ if (delay > 0) {+ await this.runtime.sleep(delay)+ }+ }+ this.times.push(this.runtime.now())+ }+}++// `retry_policy(500, 2, n)`: n attempts, sleeping 500 ms, then 1 s, then 2 s between them.+async function withRetries<T>(+ runtime: Runtime,+ attempts: number,+ action: (attempt: number) => Promise<T>,+ shouldRetry: (error: unknown) => boolean = () => true+): Promise<T> {+ for (let attempt = 0; ; attempt++) {+ try {+ return await action(attempt)+ } catch (error) {+ if (attempt + 1 >= attempts || !shouldRetry(error)) {+ throw error+ }+ await runtime.sleep(500 * 2 ** attempt)+ }+ }+}++// UUIDv7 as uuid's `now_v7`: 48-bit millisecond timestamp, version 7, variant 10, random rest.+export function uuidv7(now: number): string {+ const bytes = crypto.getRandomValues(new Uint8Array(16))+ const time = BigInt(now)+ for (let index = 0; index < 6; index++) {+ bytes[index] = Number((time >> BigInt(8 * (5 - index))) & 0xffn)+ }+ bytes[6] = (bytes[6]! & 0x0f) | 0x70+ bytes[8] = (bytes[8]! & 0x3f) | 0x80+ const hex = Buffer.from(bytes).toString('hex')+ return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`+}++interface PresignedPost {+ url: string+ fields: Record<string, string>+}++interface StartEntry {+ presigned_url: PresignedPost+ fallback_presigned_url?: PresignedPost | null+ presigned_put_url?: string | null+ fallback_presigned_put_url?: string | null+ symbol_set_id: string+}++type Target = { kind: 'put'; url: string } | { kind: 'post'; form: PresignedPost }++export class SymbolSetClient {+ private readonly throttle: Throttle+ // Set once a fallback endpoint worked after the primary failed, so later uploads skip the primary.+ private preferFallback = false++ constructor(+ private readonly runtime: Runtime,+ private readonly credentials: Credentials+ ) {+ this.throttle = new Throttle(runtime, RATE_LIMIT_PER_MINUTE)+ }++ // Project-scoped API URL, resolved the way posthog-cli's `Url::join` does.+ projectUrl(path: string): URL {+ return new URL(path, new URL(`api/projects/${this.credentials.projectId}/`, this.credentials.host))+ }++ async api(method: 'GET' | 'POST', path: string, body?: unknown): Promise<unknown> {+ await this.throttle.wait()+ const url = this.projectUrl(path)+ let response: Response+ try {+ response = await this.runtime.fetch(url, {+ method,+ headers: {+ Authorization: `Bearer ${this.credentials.apiKey}`,+ 'Content-Type': 'application/json',+ 'User-Agent': USER_AGENT,+ },+ body: body === undefined ? undefined : JSON.stringify(body),+ signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS),+ })+ } catch (error) {+ throw new ApiFailure(undefined, error instanceof Error ? error.message : String(error), url.toString())+ }+ const text = await response.text()+ if (!response.ok) {+ throw new ApiFailure(response.status, text, url.toString())+ }+ return text ? JSON.parse(text) : undefined+ }++ async upload(uploads: SymbolSetUpload[], options: UploadOptions): Promise<UploadOutcome> {+ const runId = uuidv7(this.runtime.now())+ try {+ return await this.uploadOnce(uploads, options, runId)+ } catch (error) {+ if (!(error instanceof ReleaseIdMismatch)) {+ throw error+ }+ // posthog-cli always retries the whole run without release ids when the server says a+ // chunk already belongs to another release (`--skip-release-on-fail` can't be turned off).+ return await this.uploadOnce(+ uploads.map((upload) => ({ ...upload, releaseId: null })),+ options,+ runId+ )+ }+ }++ private async uploadOnce(+ uploads: SymbolSetUpload[],+ options: UploadOptions,+ runId: string+ ): Promise<UploadOutcome> {+ const status = new Map<string, UploadStatus>()+ const contentHashes = new Map<string, string>()+ const kept: (SymbolSetUpload & { hash: string })[] = []+ for (const upload of uploads) {+ if (upload.data.length > MAX_FILE_SIZE) {+ status.set(upload.chunkId, 'too_large')+ continue+ }+ const hash = upload.contentHash ?? contentHash(upload.data)+ contentHashes.set(upload.chunkId, hash)+ kept.push({ ...upload, hash })+ }++ const needed = await this.check(kept, options)+ for (const upload of kept) {+ if (!needed.has(upload.chunkId)) {+ status.set(upload.chunkId, 'already_present')+ }+ }+ const toSend = kept.filter((upload) => needed.has(upload.chunkId))+ for (let start = 0; start < toSend.length; start += options.batchSize) {+ const batch = toSend.slice(start, start + options.batchSize)+ for (const [chunkId, result] of await this.uploadBatch(batch, options, runId)) {+ status.set(chunkId, result)+ }+ }+ return { status, contentHashes }+ }++ private entry(upload: SymbolSetUpload & { hash: string }): {+ chunk_id: string+ release_id: string | null+ content_hash: string+ content_length: number+ } {+ return {+ chunk_id: upload.chunkId,+ release_id: upload.releaseId,+ content_hash: upload.hash,+ content_length: upload.data.length,+ }+ }++ // Asks which chunks the server still needs. A failed check is not fatal: every chunk from the+ // failed slice onward is sent, and the start call decides.+ private async check(uploads: (SymbolSetUpload & { hash: string })[], options: UploadOptions): Promise<Set<string>> {+ const needed = new Set<string>()+ for (let start = 0; start < uploads.length; start += CHECK_BATCH_SIZE) {+ const slice = uploads.slice(start, start + CHECK_BATCH_SIZE)+ try {+ const response = (await withRetries(+ this.runtime,+ 3,+ () =>+ this.api('POST', 'error_tracking/symbol_sets/bulk_check_upload', {+ symbol_sets: slice.map((upload) => this.entry(upload)),+ force: options.force,+ skip_on_conflict: options.skipOnConflict,+ }),+ (error) =>+ !(+ error instanceof ApiFailure &&+ error.status !== undefined &&+ error.status >= 400 &&+ error.status < 500+ )+ )) as { chunk_ids_to_upload?: unknown }+ if (!Array.isArray(response?.chunk_ids_to_upload)) {+ throw new Error('unexpected check response')+ }+ for (const chunkId of response.chunk_ids_to_upload) {+ needed.add(String(chunkId))+ }+ } catch {+ for (const upload of uploads.slice(start)) {+ needed.add(upload.chunkId)+ }+ return needed+ }+ }+ return needed+ }++ private async uploadBatch(+ batch: (SymbolSetUpload & { hash: string })[],+ options: UploadOptions,+ runId: string+ ): Promise<Map<string, UploadStatus>> {+ const attemptId = uuidv7(this.runtime.now())+ let idMap: Record<string, StartEntry>+ try {+ const response = (await withRetries(this.runtime, 3, () =>+ this.api('POST', 'error_tracking/symbol_sets/bulk_start_upload', {+ symbol_sets: batch.map((upload) => this.entry(upload)),+ upload_attempt_id: attemptId,+ upload_run_id: runId,+ force: options.force,+ skip_on_conflict: options.skipOnConflict,+ })+ )) as { id_map?: Record<string, StartEntry> }+ idMap = response?.id_map ?? {}+ } catch (error) {+ throw startFailure(error)+ }++ const results = new Map<string, UploadStatus>()+ const byChunk = new Map(batch.map((upload) => [upload.chunkId, upload]))+ for (const upload of batch) {+ if (!(upload.chunkId in idMap)) {+ results.set(upload.chunkId, 'already_present')+ }+ }+ const entries = Object.entries(idMap)+ if (entries.length === 0) {+ return results+ }+ for (const [chunkId] of entries) {+ if (!byChunk.has(chunkId)) {+ throw new HogError(+ 'unexpected_response',+ `PostHog returned an upload URL for chunk ${chunkId}, which hog didn't send.`+ )+ }+ }+ await runWithConcurrency(entries, options.concurrency ?? 10, async ([chunkId, entry]) => {+ await this.store(byChunk.get(chunkId)!.data, entry)+ })+ const finishHashes: Record<string, string> = {}+ for (const [chunkId, entry] of entries) {+ finishHashes[entry.symbol_set_id] = byChunk.get(chunkId)!.hash+ results.set(chunkId, 'uploaded')+ }+ try {+ await withRetries(this.runtime, 3, () =>+ this.api('POST', 'error_tracking/symbol_sets/bulk_finish_upload', {+ content_hashes: finishHashes,+ upload_attempt_id: attemptId,+ upload_run_id: runId,+ })+ )+ } catch (error) {+ throw new HogError(+ 'upload_not_finished',+ `PostHog didn't confirm the upload, so the symbol sets aren't attached: ${describe(error)}`,+ 'Run the upload again. Chunks that already reached PostHog are skipped.'+ )+ }+ return results+ }++ // Sends one container to object storage. A target falls back to its alternate endpoint after two+ // transport errors in a row on the primary, like posthog-cli's endpoint router.+ private async store(data: Uint8Array, entry: StartEntry): Promise<void> {+ const primary: Target = entry.presigned_put_url+ ? { kind: 'put', url: entry.presigned_put_url }+ : { kind: 'post', form: entry.presigned_url }+ const fallbackUrl = entry.presigned_put_url ? entry.fallback_presigned_put_url : entry.fallback_presigned_url+ const fallback: Target | undefined = !fallbackUrl+ ? undefined+ : typeof fallbackUrl === 'string'+ ? { kind: 'put', url: fallbackUrl }+ : { kind: 'post', form: fallbackUrl }+ let primaryTransportErrors = 0+ let fallbackTransportErrors = 0+ await withRetries(this.runtime, fallback ? 4 : 3, async () => {+ const useFallback = fallback !== undefined && (this.preferFallback || primaryTransportErrors >= 2)+ const target = useFallback ? fallback! : primary+ let response: Response+ try {+ response = await this.send(data, target)+ } catch (error) {+ if (useFallback) {+ fallbackTransportErrors+++ } else {+ primaryTransportErrors+++ }+ throw error+ }+ if (!useFallback) {+ primaryTransportErrors = 0+ }+ if (!response.ok) {+ throw new HogError(+ 'upload_failed',+ `Object storage answered ${response.status}: ${await response.text()}`+ )+ }+ if (useFallback && primaryTransportErrors >= 2 && fallbackTransportErrors === 0) {+ this.preferFallback = true+ }+ }).catch((error) => {+ throw new HogError(+ 'upload_failed',+ `hog couldn't upload a symbol set: ${describe(error)}`,+ 'Check your network connection and run the upload again.'+ )+ })+ }++ private send(data: Uint8Array, target: Target): Promise<Response> {+ if (target.kind === 'put') {+ return this.runtime.fetch(target.url, {+ method: 'PUT',+ body: data as BodyInit,+ signal: AbortSignal.timeout(transferTimeout(data.length)),+ })+ }+ const form = new FormData()+ for (const [key, value] of Object.entries(target.form.fields)) {+ form.append(key, value)+ }+ // SeaweedFS and MinIO need a filename on the file part.+ form.append('file', new Blob([data as BlobPart]), 'file')+ return this.runtime.fetch(target.form.url, {+ method: 'POST',+ body: form,+ signal: AbortSignal.timeout(transferTimeout(data.length)),+ })+ }+}++function describe(error: unknown): string {+ return error instanceof Error ? error.message : String(error)+}++function startFailure(error: unknown): Error {+ if (error instanceof ApiFailure && error.hasCode('release_id_mismatch')) {+ return new ReleaseIdMismatch()+ }+ if (error instanceof ApiFailure && error.hasCode('content_hash_mismatch')) {+ return new HogError(+ 'content_hash_mismatch',+ 'PostHog already has a symbol set with this chunk ID and different content.',+ 'Pass --force to replace it, or --skip-on-conflict to keep the existing one.'+ )+ }+ return new HogError('upload_failed', `PostHog didn't start the upload: ${describe(error)}`)+}++async function runWithConcurrency<T>(items: T[], limit: number, work: (item: T) => Promise<void>): Promise<void> {+ let next = 0+ const workers = Array.from({ length: Math.min(limit, items.length) }, async () => {+ while (next < items.length) {+ await work(items[next++]!)+ }+ })+ await Promise.all(workers)+}++export { ApiFailure }diff --git a/hog/src/testing.ts b/hog/src/testing.tsindex c1cb77c278c1..bea016fe0b94 100644--- a/hog/src/testing.ts+++ b/hog/src/testing.ts@@ -1,3 +1,5 @@+import { existsSync, readFileSync } from 'node:fs'+import type { Prompts } from '@/core/prompts'import type { Env, Runtime } from '@/core/runtime'@@ -7,8 +9,11 @@ export interface FakeRuntimeOptions {env?: EnvstdoutIsTTY?: booleancolumns?: number+ cwd?: stringfiles?: Record<string, string>stdin?: string+ // Read files from disk instead of `files`, for commands that scan real build output.+ useDisk?: boolean// Answers to prompts, in the order hog asks them. A prompt with no answer left fails the test.answers?: string[]// Answers every API request. Without it, requests fail with HTTP 500. A string body is sent@@ -74,7 +79,16 @@ export function fakeRuntime(options: FakeRuntimeOptions = {}): FakeRuntime {clock += ms},homeDir: () => '/home/test',+ cwd: () => options.cwd ?? '/work',+ // A path exists when it is a file, or a folder some file sits under.+ exists: async (path) =>+ options.useDisk+ ? existsSync(path)+ : path in files || Object.keys(files).some((file) => file.startsWith(`${path}/`)),readFile: async (path) => {+ if (options.useDisk) {+ return readFileSync(path, 'utf8')+ }const contents = files[path]if (contents === undefined) {throw Object.assign(new Error(`ENOENT: no such file or directory, open '${path}'`), { code: 'ENOENT' })diff --git a/hog/test/parity/README.md b/hog/test/parity/README.mdnew file mode 100644index 000000000000..f0c2f3b07d35--- /dev/null+++ b/hog/test/parity/README.md@@ -0,0 +1,45 @@+# Parity with posthog-cli++`hog error-tracking` must upload exactly what `posthog-cli` uploads.+PostHog stores a content hash per chunk ID, and a re-upload with a different hash fails with `content_hash_mismatch`.+So a byte that differs between the two CLIs breaks every customer who switches from one to the other.++These tests compare hog against goldens recorded from the Rust code.+The goldens are checked in, so the tests need no Rust toolchain.++## What is compared++| Test | Golden | Recorded with |+| -------------------- | ----------------------------------------------------------------- | ----------------------------------------------------------------------- |+| `containers.test.ts` | The content hash of a symbol set container, for 47 inputs | `cli/examples/hog_parity_oracle.rs`, which calls posthog-cli's own code |+| `e2e.test.ts` | Every request the CLI sends, the uploaded bytes and the exit code | The `posthog-cli` binary against `fake-server.ts` |++The container inputs sit on every boundary where libzstd's streaming output can differ from one-shot compression: exact multiples of the 128 KiB block, the 2 MiB window, and inputs up to 32 MiB.+`inputs.ts` generates them from a seed, so large inputs are never checked in.++The end-to-end scenarios cover a first upload, a re-upload of chunks PostHog already has, the multipart POST path, content and release conflicts with and without `--force` and `--skip-on-conflict`, check and start failures, and releases from flags and from git.++## What is normalized++`normalize.ts` rewrites only values that are random by design:++- upload run and attempt IDs (UUIDv7)+- the key order of `content_hashes` and release `metadata`, which posthog-cli writes in hash-map order+- the order of object-storage uploads within one batch, which run in parallel+- the multipart boundary+- the user agent: hog sends `hog/<version>`, posthog-cli sends `posthog-cli`++Everything else is compared byte for byte, including the field order of every JSON body.++## Regenerate the goldens++Build both Rust binaries from `cli/`, then run the recorders from `hog/`:++```bash+(cd ../cli && cargo build --release && cargo build --release --example hog_parity_oracle)+TARGET=$(cd ../cli && cargo metadata --format-version 1 --no-deps | jq -r .target_directory)+bun test/parity/record-containers.ts "$TARGET/release/examples/hog_parity_oracle"+bun test/parity/record-e2e.ts "$TARGET/release/posthog-cli"+```++Regenerate them when posthog-cli changes what it uploads, and review the diff: a changed golden means hog and posthog-cli no longer agree until hog changes too.diff --git a/hog/test/parity/containers.test.ts b/hog/test/parity/containers.test.tsnew file mode 100644index 000000000000..29c5d9c22a28--- /dev/null+++ b/hog/test/parity/containers.test.ts@@ -0,0 +1,31 @@+import { describe, expect, test } from 'bun:test'++import { contentHash, SymbolDataType, writeSymbolData } from '@/error-tracking/container'++import golden from './golden/containers.json'+import { generateInput } from './inputs'++const TYPES = {+ proguard: SymbolDataType.ProguardMapping,+ hermes: SymbolDataType.HermesMap,+ dsym: SymbolDataType.AppleDsym,+ elf: SymbolDataType.ElfDebugInfo,+} as const++// Each golden comes from posthog-cli's own container code (cli/examples/hog_parity_oracle.rs). A+// mismatch here means hog would upload different bytes than posthog-cli, and PostHog would reject+// a re-upload of the same file with `content_hash_mismatch`.+describe('symbol set containers match posthog-cli byte for byte', () => {+ test.each(+ golden.map(+ (testCase) =>+ [`${testCase.type} ${testCase.input.generator} ${testCase.input.size} bytes`, testCase] as const+ )+ )('%s', (_name, testCase) => {+ const container = writeSymbolData(+ TYPES[testCase.type as keyof typeof TYPES],+ generateInput(testCase.input as never)+ )+ expect(contentHash(container)).toBe(testCase.hash)+ })+})diff --git a/hog/test/parity/containers.ts b/hog/test/parity/containers.tsnew file mode 100644index 000000000000..a235327712a3--- /dev/null+++ b/hog/test/parity/containers.ts@@ -0,0 +1,44 @@+import type { InputSpec } from './inputs'++export interface ContainerCase {+ type: 'proguard' | 'hermes' | 'dsym' | 'elf'+ input: InputSpec+}++const BLOCK = 128 * 1024+const WINDOW = 2 * 1024 * 1024++// Sizes around every boundary where libzstd's streaming output can differ from one-shot+// compression: the 128 KiB block (exact multiples get an extra empty last block in Rust), the 2 MiB+// window at level 3, and large inputs that use the circular input buffer.+const SIZES = [+ 0,+ 1,+ 1000,+ BLOCK - 1,+ BLOCK,+ BLOCK + 1,+ 2 * BLOCK,+ 3 * BLOCK,+ WINDOW - 1,+ WINDOW,+ WINDOW + 1,+ WINDOW + BLOCK,+ 3_000_000,+ 4 * WINDOW,+ 4 * WINDOW + 1,+]++export const CONTAINER_CASES: ContainerCase[] = [+ ...SIZES.map(+ (size, index): ContainerCase => ({ type: 'proguard', input: { generator: 'lines', seed: 1000 + index, size } })+ ),+ ...SIZES.map(+ (size, index): ContainerCase => ({ type: 'proguard', input: { generator: 'ascii', seed: 2000 + index, size } })+ ),+ ...SIZES.map(+ (size, index): ContainerCase => ({ type: 'elf', input: { generator: 'bytes', seed: 3000 + index, size } })+ ),+ { type: 'dsym', input: { generator: 'bytes', seed: 4000, size: 32 * 1024 * 1024 } },+ { type: 'hermes', input: { generator: 'ascii', seed: 5000, size: 5 * BLOCK } },+]diff --git a/hog/test/parity/e2e.test.ts b/hog/test/parity/e2e.test.tsnew file mode 100644index 000000000000..4be262e997b0--- /dev/null+++ b/hog/test/parity/e2e.test.ts@@ -0,0 +1,19 @@+import { describe, expect, test } from 'bun:test'+import { readFileSync } from 'node:fs'+import { join } from 'node:path'++import { runScenario, type ParityResult } from './run'+import { SCENARIOS } from './scenarios'++// Each golden is what posthog-cli sent to the fake server for the same files and flags+// (record-e2e.ts). hog must send the same requests, with the same bodies and uploaded bytes, and+// exit with the same code.+describe('hog error-tracking sends what posthog-cli sends', () => {+ test.each(SCENARIOS.map((scenario) => [scenario.name, scenario] as const))('%s', async (name, scenario) => {+ const golden = JSON.parse(+ readFileSync(join(import.meta.dir, 'golden', 'e2e', `${name}.json`), 'utf8')+ ) as ParityResult+ const result = await runScenario(scenario, 'hog')+ expect(result).toEqual(golden)+ })+})diff --git a/hog/test/parity/fake-server.ts b/hog/test/parity/fake-server.tsnew file mode 100644index 000000000000..b92f44bea6e9--- /dev/null+++ b/hog/test/parity/fake-server.ts@@ -0,0 +1,245 @@+import { createHash } from 'node:crypto'++// A fake PostHog API plus object store that records every request. Parity tests run posthog-cli and+// hog against it and compare the recordings. Server-side ids are derived from the request (UUIDv5),+// so both CLIs see the same ids.++export type Scenario = 'fresh' | 'post-only' | 'hash-mismatch' | 'release-mismatch' | 'check-403' | 'start-500-once'++export interface RecordedRequest {+ method: string+ path: string+ headers: Record<string, string>+ // API bodies as text. Object-storage bodies are summarized, because they are containers.+ body?: string+ upload?: { sha512: string; length: number; fields?: Record<string, string>; filename?: string }+ status: number+}++export interface FakeServer {+ url: string+ requests: RecordedRequest[]+ seed(entries: { chunkId: string; contentHash: string; releaseId?: string | null }[]): void+ stop(): void+}++const NAMESPACE = Buffer.from('6ba7b8119dad11d180b400c04fd430c8', 'hex')++function uuid5(name: string): string {+ const hash = createHash('sha1').update(NAMESPACE).update(name).digest()+ hash[6] = (hash[6]! & 0x0f) | 0x50+ hash[8] = (hash[8]! & 0x3f) | 0x80+ const hex = hash.subarray(0, 16).toString('hex')+ return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`+}++interface StoredSymbolSet {+ id: string+ hash: string | null+ releaseId: string | null+}++const RECORDED_HEADERS = ['authorization', 'content-type', 'user-agent']++export function startFakeServer(scenario: Scenario): FakeServer {+ const requests: RecordedRequest[] = []+ const symbolSets = new Map<string, StoredSymbolSet>()+ const releases = new Map<string, unknown>()+ let startCalls = 0++ const json = (status: number, body: unknown): Response =>+ new Response(JSON.stringify(body), { status, headers: { 'content-type': 'application/json' } })+ const apiError = (status: number, code: string, detail: string): Response =>+ json(status, { type: 'validation_error', code, detail, attr: null })++ const server = Bun.serve({+ port: 0,+ hostname: '127.0.0.1',+ async fetch(request) {+ const url = new URL(request.url)+ const headers: Record<string, string> = {}+ for (const name of RECORDED_HEADERS) {+ const value = request.headers.get(name)+ if (value !== null) {+ headers[name] = name === 'authorization' ? value.replace(/phx_\w+/, 'phx_<key>') : value+ }+ }+ const entry: RecordedRequest = {+ method: request.method,+ path: url.pathname + url.search,+ headers,+ status: 0,+ }+ requests.push(entry)+ const respond = (response: Response): Response => {+ entry.status = response.status+ return response+ }++ if (url.pathname.startsWith('/s3/')) {+ return respond(await storeObject(request, url, entry))+ }+ const body = await request.text()+ if (body) {+ entry.body = body+ }+ const path = url.pathname.replace(/\/$/, '')+ const base = `http://127.0.0.1:${server.port}`+ let match: RegExpMatchArray | null++ if ((match = path.match(/^\/api\/projects\/\d+\/error_tracking\/releases\/hash\/(.+)$/))) {+ const release = releases.get(match[1]!)+ return respond(+ release+ ? json(200, release)+ : json(404, { type: 'invalid_request', code: 'not_found', detail: 'Not found.', attr: null })+ )+ }+ if (/^\/api\/projects\/\d+\/error_tracking\/releases$/.test(path) && request.method === 'POST') {+ const parsed = JSON.parse(body) as {+ hash_id: string+ version: string+ project: string+ metadata?: unknown+ }+ const release = {+ id: uuid5(`release:${parsed.hash_id}`),+ hash_id: parsed.hash_id,+ version: parsed.version,+ project: parsed.project,+ }+ releases.set(parsed.hash_id, release)+ return respond(json(201, release))+ }+ if (path.endsWith('/symbol_sets/bulk_check_upload')) {+ if (scenario === 'check-403') {+ return respond(+ json(403, {+ type: 'authentication_error',+ code: 'permission_denied',+ detail: 'No.',+ attr: null,+ })+ )+ }+ const parsed = JSON.parse(body) as { symbol_sets: { chunk_id: string; content_hash: string }[] }+ const needed = parsed.symbol_sets+ .filter((set) => symbolSets.get(set.chunk_id)?.hash !== set.content_hash)+ .map((set) => set.chunk_id)+ return respond(json(200, { chunk_ids_to_upload: needed }))+ }+ if (path.endsWith('/symbol_sets/bulk_start_upload')) {+ startCalls+++ if (scenario === 'start-500-once' && startCalls === 1) {+ return respond(json(500, { detail: 'Server error.' }))+ }+ const parsed = JSON.parse(body) as {+ symbol_sets: {+ chunk_id: string+ release_id: string | null+ content_hash: string+ content_length?: number+ }[]+ force: boolean+ skip_on_conflict: boolean+ }+ // The stored copy has other content: an error unless the request says what to do.+ if (scenario === 'hash-mismatch' && !parsed.force) {+ if (!parsed.skip_on_conflict) {+ return respond(+ apiError(+ 400,+ 'content_hash_mismatch',+ 'A symbol set with this chunk ID already has different content.'+ )+ )+ }+ return respond(json(201, { id_map: {} }))+ }+ if (scenario === 'release-mismatch' && parsed.symbol_sets.some((set) => set.release_id !== null)) {+ return respond(+ apiError(400, 'release_id_mismatch', 'The symbol set already belongs to another release.')+ )+ }+ const idMap: Record<string, unknown> = {}+ for (const set of parsed.symbol_sets) {+ if (symbolSets.get(set.chunk_id)?.hash === set.content_hash) {+ continue+ }+ const id = uuid5(`symbol_set:${set.chunk_id}`)+ symbolSets.set(set.chunk_id, { id, hash: null, releaseId: set.release_id })+ const key = `symbolsets/${id}`+ const item: Record<string, unknown> = {+ presigned_url: {+ url: `${base}/s3/post`,+ fields: { key, policy: 'policy', 'x-amz-signature': 'signature' },+ },+ symbol_set_id: id,+ }+ if (scenario !== 'post-only' && set.content_length !== undefined) {+ item.presigned_put_url = `${base}/s3/put/${key}?length=${set.content_length}`+ }+ idMap[set.chunk_id] = item+ }+ return respond(json(201, { id_map: idMap }))+ }+ if (path.endsWith('/symbol_sets/bulk_finish_upload')) {+ const parsed = JSON.parse(body) as { content_hashes: Record<string, string> }+ for (const [id, hash] of Object.entries(parsed.content_hashes)) {+ for (const set of symbolSets.values()) {+ if (set.id === id) {+ set.hash = hash+ }+ }+ }+ return respond(json(201, { success: true }))+ }+ return respond(json(404, { detail: `No fake for ${request.method} ${url.pathname}` }))+ },+ })++ return {+ url: `http://127.0.0.1:${server.port}`,+ requests,+ seed(entries) {+ for (const entry of entries) {+ symbolSets.set(entry.chunkId, {+ id: uuid5(`symbol_set:${entry.chunkId}`),+ hash: entry.contentHash,+ releaseId: entry.releaseId ?? null,+ })+ }+ },+ stop: () => server.stop(true),+ }+}++async function storeObject(request: Request, url: URL, entry: RecordedRequest): Promise<Response> {+ if (request.method === 'PUT') {+ const body = new Uint8Array(await request.arrayBuffer())+ entry.upload = { sha512: createHash('sha512').update(body).digest('hex'), length: body.length }+ // A presigned PUT signs the content length, so a different length fails like it does on S3.+ if (Number(url.searchParams.get('length')) !== body.length) {+ return new Response('<Error>SignatureDoesNotMatch</Error>', { status: 403 })+ }+ return new Response(null, { status: 200 })+ }+ const form = await request.formData()+ const fields: Record<string, string> = {}+ let file: File | undefined+ for (const [name, value] of form.entries()) {+ if (typeof value === 'string') {+ fields[name] = value+ } else {+ file = value+ }+ }+ const body = file ? new Uint8Array(await file.arrayBuffer()) : new Uint8Array()+ entry.upload = {+ sha512: createHash('sha512').update(body).digest('hex'),+ length: body.length,+ fields,+ filename: file?.name,+ }+ return new Response(null, { status: 204 })+}diff --git a/hog/test/parity/fixtures.ts b/hog/test/parity/fixtures.tsnew file mode 100644index 000000000000..d21c76eb2c54--- /dev/null+++ b/hog/test/parity/fixtures.ts@@ -0,0 +1,45 @@+import { mkdirSync, writeFileSync } from 'node:fs'+import { dirname, join } from 'node:path'++// Fixture files written into a fresh folder per run, outside any git repository unless a scenario+// builds one, so neither CLI picks up the machine's own git or CI state.++export const SMALL_MAPPING = [+ '# compiler: R8',+ '# compiler_version: 8.2.47',+ 'com.example.app.MainActivity -> com.example.app.MainActivity:',+ ' 1:1:void <init>():12:12 -> <init>',+ ' 1:4:void onCreate(android.os.Bundle):16:19 -> onCreate',+ 'com.example.app.Model -> a.a:',+ ' java.lang.String name -> a',+ ' 1:1:java.lang.String getName():8:8 -> a',+ '',+].join('\n')++export function mappingOfSize(size: number): string {+ const lines = ['com.example.app.Big -> a.b:']+ let index = 0+ let text = `${lines[0]}\n`+ while (text.length < size - 200) {+ text += ` ${index}:${index}:void method${index}(int):${index}:${index} -> m${index % 97}\n`+ index+++ }+ const padding = size - text.length - 3+ return `${text}# ${'x'.repeat(padding)}\n`+}++export function write(folder: string, files: Record<string, string | Uint8Array>): void {+ for (const [path, contents] of Object.entries(files)) {+ const full = join(folder, path)+ mkdirSync(dirname(full), { recursive: true })+ writeFileSync(full, contents)+ }+}++// A minimal repository on disk: what posthog-cli and hog read without running git.+export const GIT_REPO: Record<string, string> = {+ '.git/HEAD': 'ref: refs/heads/main\n',+ '.git/refs/heads/main': 'c0ffee00c0ffee00c0ffee00c0ffee00c0ffee00\n',+ '.git/config':+ '[core]\n\tbare = false\n[remote "origin"]\n\turl = https://x-access-token:[email protected]/PostHog/example-app.git\n\tfetch = +refs/heads/*:refs/remotes/origin/*\n',+}diff --git a/hog/test/parity/golden/containers.json b/hog/test/parity/golden/containers.jsonnew file mode 100644index 000000000000..4092b0e79b12--- /dev/null+++ b/hog/test/parity/golden/containers.json@@ -0,0 +1,425 @@+[+ {+ "type": "proguard",+ "input": {+ "generator": "lines",+ "seed": 1000,+ "size": 0+ },+ "hash": "0feb4aa5d6d8b5131455d9809d4356bd9a98d63babf12b1efc2eb20349de5e8e484b0e79dbfd0e0eb533af64e6803ec7e5f2a32eaa44a57c41256d2ac5ba7f86"+ },+ {+ "type": "proguard",+ "input": {+ "generator": "lines",+ "seed": 1001,+ "size": 1+ },+ "hash": "64d4653dbe9e4b6ff6f5fc853d891eda904111c4570803406a98efe04b931e2c0854c99c6d3b7dce5335ae550117ba9e1710efa6f636f174e08fda57c4b57e8f"+ },+ {+ "type": "proguard",+ "input": {+ "generator": "lines",+ "seed": 1002,+ "size": 1000+ },+ "hash": "7b160a1fbeb5825729f9d91896821fbcaebacc30b06d3ce224ff2d9f5349389cb869d31e83b09903729ac4863861684f577475b50f86d51f664b7cfb2ec7283c"+ },+ {+ "type": "proguard",+ "input": {+ "generator": "lines",+ "seed": 1003,+ "size": 131071+ },+ "hash": "6bf65e4a328ef498c3ee2cf9eba1c1eb99385cf9e6ff45653544cd0c31f933d4db4c90990931eb81cf320acbfdfad7137b8937ba80e9b44e2a243b988c2f76b8"+ },+ {+ "type": "proguard",+ "input": {+ "generator": "lines",+ "seed": 1004,+ "size": 131072+ },+ "hash": "851ad4b88cb87ce5b6de34931e433f398b48b95b9b4f61787a66b19aee518206da52bae6ced327ecff1ec771973cf7b96fe7f4644aef4dae32add568d44ba667"+ },+ {+ "type": "proguard",+ "input": {+ "generator": "lines",+ "seed": 1005,+ "size": 131073+ },+ "hash": "dbde378cdc38497b83cafbb484cdae38e0a6cebc467492bb1578d761383be072e719a34b8918ad50b0e01942e6b491848d08a7c827d42014acb9928fd1bc2abe"+ },+ {+ "type": "proguard",+ "input": {+ "generator": "lines",+ "seed": 1006,+ "size": 262144+ },+ "hash": "e9d12ced337c7df2e80fd2753e03c993ee6d372a68156cbded67211010fbee9cd591d63cef9e5addc02e2d912310e327528d48d124a84e62b859f16f7a4df834"+ },+ {+ "type": "proguard",+ "input": {+ "generator": "lines",+ "seed": 1007,+ "size": 393216+ },+ "hash": "46591380dc3535e44aea12b4491e97544210da95fac63847fb06910a421011fb6111175f9ff4b075c9c11df18ed97b06253767ef90131d77c5a5d3cf61b8ba4d"+ },+ {+ "type": "proguard",+ "input": {+ "generator": "lines",+ "seed": 1008,+ "size": 2097151+ },+ "hash": "2a7088c74e6f350e0c384c756c58a22a0cc511425c35d6f7e1c8d58ddffdf50452ee9855211d640a6dd2a0469c1c7442a0e4ef79d15f795d1c3caa68eb916a2b"+ },+ {+ "type": "proguard",+ "input": {+ "generator": "lines",+ "seed": 1009,+ "size": 2097152+ },+ "hash": "796955409d5eddac5d5c107d9d8dc1ffeab71b9ec399f2efb42ca52512caf4f1c6596829b3b79e460dbe04142c316fdb511f67c4565d5f6315f4d9293854a737"+ },+ {+ "type": "proguard",+ "input": {+ "generator": "lines",+ "seed": 1010,+ "size": 2097153+ },+ "hash": "b6d5fcb1abcda1d7034ab95a55bc88d22549ced7bab81e11e05cb5e2dba097e4061bb257b2dd2ac2e44bd3f7b3e6e64a1b4ff244ee1811f92d42c46417c70bef"+ },+ {+ "type": "proguard",+ "input": {+ "generator": "lines",+ "seed": 1011,+ "size": 2228224+ },+ "hash": "22c18046ad494252abc4e5895be35c50220b868a903ccbae9ac6a7e2f00b4d72f3af0313e140b034298b71caad0e7322f6f7870377e9db62bf9d1881cb9cd6c8"+ },+ {+ "type": "proguard",+ "input": {+ "generator": "lines",+ "seed": 1012,+ "size": 3000000+ },+ "hash": "5bf6e370ff1b984f06a43545dd99ed929bab393ddea4b3aa071806b659d268442941689d27e6fe67ab4f23112a09d65eaf20b83b54533a2b437e12310b9f143f"+ },+ {+ "type": "proguard",+ "input": {+ "generator": "lines",+ "seed": 1013,+ "size": 8388608+ },+ "hash": "b60e56653bfea3eb24fe5c72970a1df639e4cc01c5bc2dd082d9e8ef551f89a0912664c1faad4ab2b478208f40f6009d0d41c396324d77e469464b28c1605797"+ },+ {+ "type": "proguard",+ "input": {+ "generator": "lines",+ "seed": 1014,+ "size": 8388609+ },+ "hash": "b85e71d26f42d3a3a0b86d2a18f46bfd38291374c92f440f1b2a50bf19ec3f1b2a882239887587dd26aa3ee0ee631981129c7bb760878e651fc592bb4f486fbe"+ },+ {+ "type": "proguard",+ "input": {+ "generator": "ascii",+ "seed": 2000,+ "size": 0+ },+ "hash": "0feb4aa5d6d8b5131455d9809d4356bd9a98d63babf12b1efc2eb20349de5e8e484b0e79dbfd0e0eb533af64e6803ec7e5f2a32eaa44a57c41256d2ac5ba7f86"+ },+ {+ "type": "proguard",+ "input": {+ "generator": "ascii",+ "seed": 2001,+ "size": 1+ },+ "hash": "2c0c9fc60305f34f09e6acd7c19dbb5759328703b5cf0ffbbe28ba9cf6d776ea15742047e6a733747ec8737a7e78f75c087ba19d25622456841f5d378ab27740"+ },+ {+ "type": "proguard",+ "input": {+ "generator": "ascii",+ "seed": 2002,+ "size": 1000+ },+ "hash": "ba86c431301a99049ee2274881bafa48fc826bf6aed2b3534adf98be5f37cf98bb5022a7885f1533f70975d37021bae79cdc2168291d228c86858cc372161715"+ },+ {+ "type": "proguard",+ "input": {+ "generator": "ascii",+ "seed": 2003,+ "size": 131071+ },+ "hash": "8d1e0dd56908778cd92a9082c2400901556c3fc2893e90d034e007ba80b7fce6455999ff22e962b0e7c49032fe982243042fa97ebda087d6a963f5ff619d0f44"+ },+ {+ "type": "proguard",+ "input": {+ "generator": "ascii",+ "seed": 2004,+ "size": 131072+ },+ "hash": "d2f38799bf2c094d94b4129c4dc35b034c16a6576afc42078357d3503630a1e7a13d06edbbc1d164feccc873b82cda34791aba43b4e60700ba808e82ee44bc93"+ },+ {+ "type": "proguard",+ "input": {+ "generator": "ascii",+ "seed": 2005,+ "size": 131073+ },+ "hash": "4b6d0be8a0dcef79b646f1894a513e80793636f02531101b4cd6941e4fce07be02abcb4fb5ab8913857ac7344a7316eaab1d4033e733ed5ba1e8381670c387f9"+ },+ {+ "type": "proguard",+ "input": {+ "generator": "ascii",+ "seed": 2006,+ "size": 262144+ },+ "hash": "d1fd73507e4d412fc165641fca5703e08eeecb9a94c0303a75faea63c5d89453375a03ed461c7a0976339283f1b9c8754cf52821fbc3fd7864a3529d1bd22c97"+ },+ {+ "type": "proguard",+ "input": {+ "generator": "ascii",+ "seed": 2007,+ "size": 393216+ },+ "hash": "85c833bdb26c4effdcae2132b4078a06c3ebc236429d1aa148b8b1a531b09ddc33cd7b3df61df4c4e5788844b9cf8c76ef9545b643f73d36aede79ddef84e061"+ },+ {+ "type": "proguard",+ "input": {+ "generator": "ascii",+ "seed": 2008,+ "size": 2097151+ },+ "hash": "56a526bcae3bcf314ae5996b4fed6f2ad416419a8fd2800d4344f992e1e9a7e35d0e435b9e620669920bdea6de5dd714496269cf127353e05c15bc7900d2c772"+ },+ {+ "type": "proguard",+ "input": {+ "generator": "ascii",+ "seed": 2009,+ "size": 2097152+ },+ "hash": "1c743301659beba8e45835a6fe9c6a7542aad71eb84f55abfc37aa9e4f4263e8cb69684d2502373878a4aca5a936b2443a89441ca7947901522dc81b0255ee1d"+ },+ {+ "type": "proguard",+ "input": {+ "generator": "ascii",+ "seed": 2010,+ "size": 2097153+ },+ "hash": "fb8ccb86b24dcca98b1f4a8d3d3ee4cf123cf401a5f5af4a560887e57d69e45f2e57c61155702385ca925daae945d036e4f99aa9124054ed117b9d69d58f0732"+ },+ {+ "type": "proguard",+ "input": {+ "generator": "ascii",+ "seed": 2011,+ "size": 2228224+ },+ "hash": "3ab4a124477e8947a215d9f89589fecda3903e156caf9bafe1bba58de5b547bd7cf6731a12871569d37fd9cf3c5becba80637a556d9e40c2bdfb6a883571248d"+ },+ {+ "type": "proguard",+ "input": {+ "generator": "ascii",+ "seed": 2012,+ "size": 3000000+ },+ "hash": "e17458e86b4a054f47e1054eeb228bc5e1529856e2e775e1d32ddbb6ccb2c7db31515345b6c8e2f25bdb2b02ce18794f858d48201f733ef31f0764af6293dc84"+ },+ {+ "type": "proguard",+ "input": {+ "generator": "ascii",+ "seed": 2013,+ "size": 8388608+ },+ "hash": "a2148b2998e30c4976c2f19c131e01508cdfed53ddc35df2d5f30c2ca9bf28d0a89b7ab22889d362cf52591eee4f369d3a15e3b721d79c7498ee9b6db7b52db1"+ },+ {+ "type": "proguard",+ "input": {+ "generator": "ascii",+ "seed": 2014,+ "size": 8388609+ },+ "hash": "07f2e54d1e8ac9d8ba431186d82735e92c2793247413f6ebf3e8b79fcba66cda566c36cc07890ab0c354df3b8065c5850e736969cf68cb5899195fdae2a0a3b9"+ },+ {+ "type": "elf",+ "input": {+ "generator": "bytes",+ "seed": 3000,+ "size": 0+ },+ "hash": "c5328d625e21b00c77967715c047022eff6cada2b150a39f08e08c6e5bd7871feee266e8efee570d471c555f35c9d2fdaf218019f39883aa2d6ec39d2787fd16"+ },+ {+ "type": "elf",+ "input": {+ "generator": "bytes",+ "seed": 3001,+ "size": 1+ },+ "hash": "951f15b6576602febc1c28eb9b3cf0988bcb69632eca6995130d8af75edf2a69a4093ff8fedd86678285adad55cd6e498794d1fb6d051a4e1c149a4c1eb60bd3"+ },+ {+ "type": "elf",+ "input": {+ "generator": "bytes",+ "seed": 3002,+ "size": 1000+ },+ "hash": "51fd8ea415cfb87b342f21687773ccc9c744998b4c29abdeb7ce8a55794b5c033ec5cf6ecebf9b3942ff8703508619e656136e7f3012fb55bd60aab9b02fab2b"+ },+ {+ "type": "elf",+ "input": {+ "generator": "bytes",+ "seed": 3003,+ "size": 131071+ },+ "hash": "bdaa1d36c8d667b923ee409b656651577a963623d688c5bd75ab6c9b3d3b153555b706c24ef97de2d4fd1978b3b052d8e538c77583082119e36dd0b4ccb684fe"+ },+ {+ "type": "elf",+ "input": {+ "generator": "bytes",+ "seed": 3004,+ "size": 131072+ },+ "hash": "b21104240afb3622d968f5880460ef448147ce6ae55a653aba1148bc73ba72566942a98d5ae989dc86f90916d6e90da093bb487688b52ee3a83888c474943e23"+ },+ {+ "type": "elf",+ "input": {+ "generator": "bytes",+ "seed": 3005,+ "size": 131073+ },+ "hash": "a9960ece7149a300c8ff361d0cc824867fbb291f9f6b4c0fde7af30563ff8fa6f50f0f5039c180e0afeea5d624b698e5d95d32a5d9922462b9ae05d72db274dd"+ },+ {+ "type": "elf",+ "input": {+ "generator": "bytes",+ "seed": 3006,+ "size": 262144+ },+ "hash": "16cace4a111a8b8e580748baa4091ebe49011846358f6cbefa556c91c43da6af89921ff8f4b986fd2d76efb48e7d04e2929f722c19a1da80288128f3dbbc77e1"+ },+ {+ "type": "elf",+ "input": {+ "generator": "bytes",+ "seed": 3007,+ "size": 393216+ },+ "hash": "0f8cfec509edd5784d59008ddc173e2db19cf0afc61f2c639308f0394d88a6bc55d25a1e788e612f542675423315ba824cf5a5a6315284a12d5ac17aaf6d1ff4"+ },+ {+ "type": "elf",+ "input": {+ "generator": "bytes",+ "seed": 3008,+ "size": 2097151+ },+ "hash": "b76cc438a083d24684d6fe41809d1481e3a6c26a7397a236d4fb88efa004e1e1956644914d52835f018466e2cf3faa6550c559c578382cf5361eb99a37a91447"+ },+ {+ "type": "elf",+ "input": {+ "generator": "bytes",+ "seed": 3009,+ "size": 2097152+ },+ "hash": "f98bbf7b8abece501c6de50c039e4697bb5c9bef8280932b0a9bf8566c62d625c842606242a342732fde6498585b62e208e240aac13f0eaf7da86bd88cc0e0e2"+ },+ {+ "type": "elf",+ "input": {+ "generator": "bytes",+ "seed": 3010,+ "size": 2097153+ },+ "hash": "965d19f0f1970490ce599c51b89a3cf451d8df5f75dc4bedf1732bc8e68c9a99babd5d3dffdf9fded1e8a4fbd18e7b73f285c7c3adf9ad02fa93236477fb3301"+ },+ {+ "type": "elf",+ "input": {+ "generator": "bytes",+ "seed": 3011,+ "size": 2228224+ },+ "hash": "33dd774b31631fa94731ece041bf5cc79b29e8298fe98c5370620bf6eb8bf267cb40088cde7190c269b5ff87d71c8ddb1c56b75a05f2e803e8587a3483095e2c"+ },+ {+ "type": "elf",+ "input": {+ "generator": "bytes",+ "seed": 3012,+ "size": 3000000+ },+ "hash": "04006af60f8d4c9cf3cfdf1134a4708d020de73630bc7be881d9b6e87dbc1f85a1c154ffefc368579afa5f85f4967b08745998f23b7ac2ef9ad00ac870643f8b"+ },+ {+ "type": "elf",+ "input": {+ "generator": "bytes",+ "seed": 3013,+ "size": 8388608+ },+ "hash": "6793955cb6b8eca32460ede367d715b13b68f78d0d246c8fd985706220db336e333ed2a8c8a42523af9158e3d1f9b0ff08b189a5a1dca1263ecf7255a36e5277"+ },+ {+ "type": "elf",+ "input": {+ "generator": "bytes",+ "seed": 3014,+ "size": 8388609+ },+ "hash": "3834b810463fbe944c12e9d68a7dde344db4fe3e019664382bd9a7dd71c7d2cd785de5f11aa825b9f2d8c0601a821b44c32b37b5884da32dbc22473c50ee6cb7"+ },+ {+ "type": "dsym",+ "input": {+ "generator": "bytes",+ "seed": 4000,+ "size": 33554432+ },+ "hash": "120b0bcd3c58bb94c9a0a7ab8cb97cd19daa403a7e830888a4a90713e50d8c905d72f9edac0a3ac072dbcf2868cf6d2328aabee80f7e367ff1c241c47165d716"+ },+ {+ "type": "hermes",+ "input": {+ "generator": "ascii",+ "seed": 5000,+ "size": 655360+ },+ "hash": "8c303d48c20e81fdcaab24836b1b394d127e72035bc7651167a2707c07c608b698c635cf47f389064612009943257e8684ee124f838e0db30da36973304f4822"+ }+]diff --git a/hog/test/parity/golden/e2e/proguard-already-present.json b/hog/test/parity/golden/e2e/proguard-already-present.jsonnew file mode 100644index 000000000000..675b994f64bb--- /dev/null+++ b/hog/test/parity/golden/e2e/proguard-already-present.json@@ -0,0 +1,24 @@+{+ "exitCode": 0,+ "requests": [+ {+ "method": "GET",+ "path": "/api/projects/1/error_tracking/releases/hash/f5bacd280427e2a06b06ddd5097489794b66ed56bdb85fb8b63a43fca2a2953c45cb348dcf37e252f57d875333b773a1664ade7c5cc02e221eae47b13d3a03d3",+ "headers": {+ "authorization": "Bearer phx_<key>",+ "content-type": "application/json"+ },+ "status": 200+ },+ {+ "method": "POST",+ "path": "/api/projects/1/error_tracking/symbol_sets/bulk_check_upload",+ "headers": {+ "authorization": "Bearer phx_<key>",+ "content-type": "application/json"+ },+ "body": "{\"symbol_sets\":[{\"chunk_id\":\"map-already-present\",\"release_id\":\"f845c163-4530-518a-9806-6241506198ca\",\"content_hash\":\"72e221661b7a13caab866c5782dc0c99890c67d568fea7d4f9775d7917e1be3dbccca94b7e08ef7ed4ff6485f52db9c93f4fa209e9a82330bed1981bf99b495c\",\"content_length\":222}],\"force\":false,\"skip_on_conflict\":false}",+ "status": 200+ }+ ]+}diff --git a/hog/test/parity/golden/e2e/proguard-block-multiple.json b/hog/test/parity/golden/e2e/proguard-block-multiple.jsonnew file mode 100644index 000000000000..2c47ebc8c947--- /dev/null+++ b/hog/test/parity/golden/e2e/proguard-block-multiple.json@@ -0,0 +1,47 @@+{+ "exitCode": 0,+ "requests": [+ {+ "method": "POST",+ "path": "/api/projects/1/error_tracking/symbol_sets/bulk_check_upload",+ "headers": {+ "authorization": "Bearer phx_<key>",+ "content-type": "application/json"+ },+ "body": "{\"symbol_sets\":[{\"chunk_id\":\"map-block-multiple\",\"release_id\":null,\"content_hash\":\"5a611bc8e040902ed735b207a8ac582613efbbfb62e34fc018072e6e14db88bd80c70aebad2c2623d37db56dcd8e0c55e748ad9874c8d5ae93aa2a7e2d739f1c\",\"content_length\":35949}],\"force\":false,\"skip_on_conflict\":false}",+ "status": 200+ },+ {+ "method": "POST",+ "path": "/api/projects/1/error_tracking/symbol_sets/bulk_start_upload",+ "headers": {+ "authorization": "Bearer phx_<key>",+ "content-type": "application/json"+ },+ "body": "{\"symbol_sets\":[{\"chunk_id\":\"map-block-multiple\",\"release_id\":null,\"content_hash\":\"5a611bc8e040902ed735b207a8ac582613efbbfb62e34fc018072e6e14db88bd80c70aebad2c2623d37db56dcd8e0c55e748ad9874c8d5ae93aa2a7e2d739f1c\",\"content_length\":35949}],\"upload_attempt_id\":\"<attempt-1>\",\"upload_run_id\":\"<run>\",\"force\":false,\"skip_on_conflict\":false}",+ "status": 201+ },+ {+ "method": "PUT",+ "path": "/s3/put/symbolsets/28ec8947-4b7d-57de-921a-7bb7626ee1da?length=35949",+ "headers": {+ "authorization": "<none>"+ },+ "upload": {+ "sha512": "5a611bc8e040902ed735b207a8ac582613efbbfb62e34fc018072e6e14db88bd80c70aebad2c2623d37db56dcd8e0c55e748ad9874c8d5ae93aa2a7e2d739f1c",+ "length": 35949+ },+ "status": 200+ },+ {+ "method": "POST",+ "path": "/api/projects/1/error_tracking/symbol_sets/bulk_finish_upload",+ "headers": {+ "authorization": "Bearer phx_<key>",+ "content-type": "application/json"+ },+ "body": "{\"content_hashes\":{\"28ec8947-4b7d-57de-921a-7bb7626ee1da\":\"5a611bc8e040902ed735b207a8ac582613efbbfb62e34fc018072e6e14db88bd80c70aebad2c2623d37db56dcd8e0c55e748ad9874c8d5ae93aa2a7e2d739f1c\"},\"upload_attempt_id\":\"<attempt-1>\",\"upload_run_id\":\"<run>\"}",+ "status": 201+ }+ ]+}diff --git a/hog/test/parity/golden/e2e/proguard-bom-crlf.json b/hog/test/parity/golden/e2e/proguard-bom-crlf.jsonnew file mode 100644index 000000000000..f8c707b36734--- /dev/null+++ b/hog/test/parity/golden/e2e/proguard-bom-crlf.json@@ -0,0 +1,47 @@+{+ "exitCode": 0,+ "requests": [+ {+ "method": "POST",+ "path": "/api/projects/1/error_tracking/symbol_sets/bulk_check_upload",+ "headers": {+ "authorization": "Bearer phx_<key>",+ "content-type": "application/json"+ },+ "body": "{\"symbol_sets\":[{\"chunk_id\":\"map-bom-crlf\",\"release_id\":null,\"content_hash\":\"509f0cca78d17d4717d79cf50efada5541c60b7b4bd433ef212f59b8ccdcaf947f9e2c12e966ebb0b16a9c455eacdd8d0193065d98b8af76e50eef14fc4b79d7\",\"content_length\":239}],\"force\":false,\"skip_on_conflict\":false}",+ "status": 200+ },+ {+ "method": "POST",+ "path": "/api/projects/1/error_tracking/symbol_sets/bulk_start_upload",+ "headers": {+ "authorization": "Bearer phx_<key>",+ "content-type": "application/json"+ },+ "body": "{\"symbol_sets\":[{\"chunk_id\":\"map-bom-crlf\",\"release_id\":null,\"content_hash\":\"509f0cca78d17d4717d79cf50efada5541c60b7b4bd433ef212f59b8ccdcaf947f9e2c12e966ebb0b16a9c455eacdd8d0193065d98b8af76e50eef14fc4b79d7\",\"content_length\":239}],\"upload_attempt_id\":\"<attempt-1>\",\"upload_run_id\":\"<run>\",\"force\":false,\"skip_on_conflict\":false}",+ "status": 201+ },+ {+ "method": "PUT",+ "path": "/s3/put/symbolsets/a9e737e6-1428-57ef-bbd0-b5428876bda7?length=239",+ "headers": {+ "authorization": "<none>"+ },+ "upload": {+ "sha512": "509f0cca78d17d4717d79cf50efada5541c60b7b4bd433ef212f59b8ccdcaf947f9e2c12e966ebb0b16a9c455eacdd8d0193065d98b8af76e50eef14fc4b79d7",+ "length": 239+ },+ "status": 200+ },+ {+ "method": "POST",+ "path": "/api/projects/1/error_tracking/symbol_sets/bulk_finish_upload",+ "headers": {+ "authorization": "Bearer phx_<key>",+ "content-type": "application/json"+ },+ "body": "{\"content_hashes\":{\"a9e737e6-1428-57ef-bbd0-b5428876bda7\":\"509f0cca78d17d4717d79cf50efada5541c60b7b4bd433ef212f59b8ccdcaf947f9e2c12e966ebb0b16a9c455eacdd8d0193065d98b8af76e50eef14fc4b79d7\"},\"upload_attempt_id\":\"<attempt-1>\",\"upload_run_id\":\"<run>\"}",+ "status": 201+ }+ ]+}diff --git a/hog/test/parity/golden/e2e/proguard-check-403.json b/hog/test/parity/golden/e2e/proguard-check-403.jsonnew file mode 100644index 000000000000..193bdd1333e8--- /dev/null+++ b/hog/test/parity/golden/e2e/proguard-check-403.json@@ -0,0 +1,66 @@+{+ "exitCode": 0,+ "requests": [+ {+ "method": "GET",+ "path": "/api/projects/1/error_tracking/releases/hash/f5bacd280427e2a06b06ddd5097489794b66ed56bdb85fb8b63a43fca2a2953c45cb348dcf37e252f57d875333b773a1664ade7c5cc02e221eae47b13d3a03d3",+ "headers": {+ "authorization": "Bearer phx_<key>",+ "content-type": "application/json"+ },+ "status": 404+ },+ {+ "method": "POST",+ "path": "/api/projects/1/error_tracking/releases",+ "headers": {+ "authorization": "Bearer phx_<key>",+ "content-type": "application/json"+ },+ "body": "{\"hash_id\":\"f5bacd280427e2a06b06ddd5097489794b66ed56bdb85fb8b63a43fca2a2953c45cb348dcf37e252f57d875333b773a1664ade7c5cc02e221eae47b13d3a03d3\",\"version\":\"1.0+7\",\"project\":\"com.example.app\"}",+ "status": 201+ },+ {+ "method": "POST",+ "path": "/api/projects/1/error_tracking/symbol_sets/bulk_check_upload",+ "headers": {+ "authorization": "Bearer phx_<key>",+ "content-type": "application/json"+ },+ "body": "{\"symbol_sets\":[{\"chunk_id\":\"map-check-403\",\"release_id\":\"f845c163-4530-518a-9806-6241506198ca\",\"content_hash\":\"72e221661b7a13caab866c5782dc0c99890c67d568fea7d4f9775d7917e1be3dbccca94b7e08ef7ed4ff6485f52db9c93f4fa209e9a82330bed1981bf99b495c\",\"content_length\":222}],\"force\":false,\"skip_on_conflict\":false}",+ "status": 403+ },+ {+ "method": "POST",+ "path": "/api/projects/1/error_tracking/symbol_sets/bulk_start_upload",+ "headers": {+ "authorization": "Bearer phx_<key>",+ "content-type": "application/json"+ },+ "body": "{\"symbol_sets\":[{\"chunk_id\":\"map-check-403\",\"release_id\":\"f845c163-4530-518a-9806-6241506198ca\",\"content_hash\":\"72e221661b7a13caab866c5782dc0c99890c67d568fea7d4f9775d7917e1be3dbccca94b7e08ef7ed4ff6485f52db9c93f4fa209e9a82330bed1981bf99b495c\",\"content_length\":222}],\"upload_attempt_id\":\"<attempt-1>\",\"upload_run_id\":\"<run>\",\"force\":false,\"skip_on_conflict\":false}",+ "status": 201+ },+ {+ "method": "PUT",+ "path": "/s3/put/symbolsets/64564a1a-5e36-59f2-a0e9-839681fbefe8?length=222",+ "headers": {+ "authorization": "<none>"+ },+ "upload": {+ "sha512": "72e221661b7a13caab866c5782dc0c99890c67d568fea7d4f9775d7917e1be3dbccca94b7e08ef7ed4ff6485f52db9c93f4fa209e9a82330bed1981bf99b495c",+ "length": 222+ },+ "status": 200+ },+ {+ "method": "POST",+ "path": "/api/projects/1/error_tracking/symbol_sets/bulk_finish_upload",+ "headers": {+ "authorization": "Bearer phx_<key>",+ "content-type": "application/json"+ },+ "body": "{\"content_hashes\":{\"64564a1a-5e36-59f2-a0e9-839681fbefe8\":\"72e221661b7a13caab866c5782dc0c99890c67d568fea7d4f9775d7917e1be3dbccca94b7e08ef7ed4ff6485f52db9c93f4fa209e9a82330bed1981bf99b495c\"},\"upload_attempt_id\":\"<attempt-1>\",\"upload_run_id\":\"<run>\"}",+ "status": 201+ }+ ]+}diff --git a/hog/test/parity/golden/e2e/proguard-fresh.json b/hog/test/parity/golden/e2e/proguard-fresh.jsonnew file mode 100644index 000000000000..e3ae20f293e0--- /dev/null+++ b/hog/test/parity/golden/e2e/proguard-fresh.json@@ -0,0 +1,66 @@+{+ "exitCode": 0,+ "requests": [+ {+ "method": "GET",+ "path": "/api/projects/1/error_tracking/releases/hash/f5bacd280427e2a06b06ddd5097489794b66ed56bdb85fb8b63a43fca2a2953c45cb348dcf37e252f57d875333b773a1664ade7c5cc02e221eae47b13d3a03d3",+ "headers": {+ "authorization": "Bearer phx_<key>",+ "content-type": "application/json"+ },+ "status": 404+ },+ {+ "method": "POST",+ "path": "/api/projects/1/error_tracking/releases",+ "headers": {+ "authorization": "Bearer phx_<key>",+ "content-type": "application/json"+ },+ "body": "{\"hash_id\":\"f5bacd280427e2a06b06ddd5097489794b66ed56bdb85fb8b63a43fca2a2953c45cb348dcf37e252f57d875333b773a1664ade7c5cc02e221eae47b13d3a03d3\",\"version\":\"1.0+7\",\"project\":\"com.example.app\"}",+ "status": 201+ },+ {+ "method": "POST",+ "path": "/api/projects/1/error_tracking/symbol_sets/bulk_check_upload",+ "headers": {+ "authorization": "Bearer phx_<key>",+ "content-type": "application/json"+ },+ "body": "{\"symbol_sets\":[{\"chunk_id\":\"map-fresh\",\"release_id\":\"f845c163-4530-518a-9806-6241506198ca\",\"content_hash\":\"72e221661b7a13caab866c5782dc0c99890c67d568fea7d4f9775d7917e1be3dbccca94b7e08ef7ed4ff6485f52db9c93f4fa209e9a82330bed1981bf99b495c\",\"content_length\":222}],\"force\":false,\"skip_on_conflict\":false}",+ "status": 200+ },+ {+ "method": "POST",+ "path": "/api/projects/1/error_tracking/symbol_sets/bulk_start_upload",+ "headers": {+ "authorization": "Bearer phx_<key>",+ "content-type": "application/json"+ },+ "body": "{\"symbol_sets\":[{\"chunk_id\":\"map-fresh\",\"release_id\":\"f845c163-4530-518a-9806-6241506198ca\",\"content_hash\":\"72e221661b7a13caab866c5782dc0c99890c67d568fea7d4f9775d7917e1be3dbccca94b7e08ef7ed4ff6485f52db9c93f4fa209e9a82330bed1981bf99b495c\",\"content_length\":222}],\"upload_attempt_id\":\"<attempt-1>\",\"upload_run_id\":\"<run>\",\"force\":false,\"skip_on_conflict\":false}",+ "status": 201+ },+ {+ "method": "PUT",+ "path": "/s3/put/symbolsets/dd3dbc96-0565-5f35-b814-210e6857a670?length=222",+ "headers": {+ "authorization": "<none>"+ },+ "upload": {+ "sha512": "72e221661b7a13caab866c5782dc0c99890c67d568fea7d4f9775d7917e1be3dbccca94b7e08ef7ed4ff6485f52db9c93f4fa209e9a82330bed1981bf99b495c",+ "length": 222+ },+ "status": 200+ },+ {+ "method": "POST",+ "path": "/api/projects/1/error_tracking/symbol_sets/bulk_finish_upload",+ "headers": {+ "authorization": "Bearer phx_<key>",+ "content-type": "application/json"+ },+ "body": "{\"content_hashes\":{\"dd3dbc96-0565-5f35-b814-210e6857a670\":\"72e221661b7a13caab866c5782dc0c99890c67d568fea7d4f9775d7917e1be3dbccca94b7e08ef7ed4ff6485f52db9c93f4fa209e9a82330bed1981bf99b495c\"},\"upload_attempt_id\":\"<attempt-1>\",\"upload_run_id\":\"<run>\"}",+ "status": 201+ }+ ]+}diff --git a/hog/test/parity/golden/e2e/proguard-hash-mismatch-force.json b/hog/test/parity/golden/e2e/proguard-hash-mismatch-force.jsonnew file mode 100644index 000000000000..6751940a007a--- /dev/null+++ b/hog/test/parity/golden/e2e/proguard-hash-mismatch-force.json@@ -0,0 +1,66 @@+{+ "exitCode": 0,+ "requests": [+ {+ "method": "GET",+ "path": "/api/projects/1/error_tracking/releases/hash/f5bacd280427e2a06b06ddd5097489794b66ed56bdb85fb8b63a43fca2a2953c45cb348dcf37e252f57d875333b773a1664ade7c5cc02e221eae47b13d3a03d3",+ "headers": {+ "authorization": "Bearer phx_<key>",+ "content-type": "application/json"+ },+ "status": 404+ },+ {+ "method": "POST",+ "path": "/api/projects/1/error_tracking/releases",+ "headers": {+ "authorization": "Bearer phx_<key>",+ "content-type": "application/json"+ },+ "body": "{\"hash_id\":\"f5bacd280427e2a06b06ddd5097489794b66ed56bdb85fb8b63a43fca2a2953c45cb348dcf37e252f57d875333b773a1664ade7c5cc02e221eae47b13d3a03d3\",\"version\":\"1.0+7\",\"project\":\"com.example.app\"}",+ "status": 201+ },+ {+ "method": "POST",+ "path": "/api/projects/1/error_tracking/symbol_sets/bulk_check_upload",+ "headers": {+ "authorization": "Bearer phx_<key>",+ "content-type": "application/json"+ },+ "body": "{\"symbol_sets\":[{\"chunk_id\":\"map-hash-mismatch-force\",\"release_id\":\"f845c163-4530-518a-9806-6241506198ca\",\"content_hash\":\"72e221661b7a13caab866c5782dc0c99890c67d568fea7d4f9775d7917e1be3dbccca94b7e08ef7ed4ff6485f52db9c93f4fa209e9a82330bed1981bf99b495c\",\"content_length\":222}],\"force\":true,\"skip_on_conflict\":false}",+ "status": 200+ },+ {+ "method": "POST",+ "path": "/api/projects/1/error_tracking/symbol_sets/bulk_start_upload",+ "headers": {+ "authorization": "Bearer phx_<key>",+ "content-type": "application/json"+ },+ "body": "{\"symbol_sets\":[{\"chunk_id\":\"map-hash-mismatch-force\",\"release_id\":\"f845c163-4530-518a-9806-6241506198ca\",\"content_hash\":\"72e221661b7a13caab866c5782dc0c99890c67d568fea7d4f9775d7917e1be3dbccca94b7e08ef7ed4ff6485f52db9c93f4fa209e9a82330bed1981bf99b495c\",\"content_length\":222}],\"upload_attempt_id\":\"<attempt-1>\",\"upload_run_id\":\"<run>\",\"force\":true,\"skip_on_conflict\":false}",+ "status": 201+ },+ {+ "method": "PUT",+ "path": "/s3/put/symbolsets/e6ba2968-ea62-5a9e-aa90-7027624fa8c3?length=222",+ "headers": {+ "authorization": "<none>"+ },+ "upload": {+ "sha512": "72e221661b7a13caab866c5782dc0c99890c67d568fea7d4f9775d7917e1be3dbccca94b7e08ef7ed4ff6485f52db9c93f4fa209e9a82330bed1981bf99b495c",+ "length": 222+ },+ "status": 200+ },+ {+ "method": "POST",+ "path": "/api/projects/1/error_tracking/symbol_sets/bulk_finish_upload",+ "headers": {+ "authorization": "Bearer phx_<key>",+ "content-type": "application/json"+ },+ "body": "{\"content_hashes\":{\"e6ba2968-ea62-5a9e-aa90-7027624fa8c3\":\"72e221661b7a13caab866c5782dc0c99890c67d568fea7d4f9775d7917e1be3dbccca94b7e08ef7ed4ff6485f52db9c93f4fa209e9a82330bed1981bf99b495c\"},\"upload_attempt_id\":\"<attempt-1>\",\"upload_run_id\":\"<run>\"}",+ "status": 201+ }+ ]+}diff --git a/hog/test/parity/golden/e2e/proguard-hash-mismatch-skip.json b/hog/test/parity/golden/e2e/proguard-hash-mismatch-skip.jsonnew file mode 100644index 000000000000..68bea4b2baa7--- /dev/null+++ b/hog/test/parity/golden/e2e/proguard-hash-mismatch-skip.json@@ -0,0 +1,44 @@+{+ "exitCode": 0,+ "requests": [+ {+ "method": "GET",+ "path": "/api/projects/1/error_tracking/releases/hash/f5bacd280427e2a06b06ddd5097489794b66ed56bdb85fb8b63a43fca2a2953c45cb348dcf37e252f57d875333b773a1664ade7c5cc02e221eae47b13d3a03d3",+ "headers": {+ "authorization": "Bearer phx_<key>",+ "content-type": "application/json"+ },+ "status": 404+ },+ {+ "method": "POST",+ "path": "/api/projects/1/error_tracking/releases",+ "headers": {+ "authorization": "Bearer phx_<key>",+ "content-type": "application/json"+ },+ "body": "{\"hash_id\":\"f5bacd280427e2a06b06ddd5097489794b66ed56bdb85fb8b63a43fca2a2953c45cb348dcf37e252f57d875333b773a1664ade7c5cc02e221eae47b13d3a03d3\",\"version\":\"1.0+7\",\"project\":\"com.example.app\"}",+ "status": 201+ },+ {+ "method": "POST",+ "path": "/api/projects/1/error_tracking/symbol_sets/bulk_check_upload",+ "headers": {+ "authorization": "Bearer phx_<key>",+ "content-type": "application/json"+ },+ "body": "{\"symbol_sets\":[{\"chunk_id\":\"map-hash-mismatch-skip\",\"release_id\":\"f845c163-4530-518a-9806-6241506198ca\",\"content_hash\":\"72e221661b7a13caab866c5782dc0c99890c67d568fea7d4f9775d7917e1be3dbccca94b7e08ef7ed4ff6485f52db9c93f4fa209e9a82330bed1981bf99b495c\",\"content_length\":222}],\"force\":false,\"skip_on_conflict\":true}",+ "status": 200+ },+ {+ "method": "POST",+ "path": "/api/projects/1/error_tracking/symbol_sets/bulk_start_upload",+ "headers": {+ "authorization": "Bearer phx_<key>",+ "content-type": "application/json"+ },+ "body": "{\"symbol_sets\":[{\"chunk_id\":\"map-hash-mismatch-skip\",\"release_id\":\"f845c163-4530-518a-9806-6241506198ca\",\"content_hash\":\"72e221661b7a13caab866c5782dc0c99890c67d568fea7d4f9775d7917e1be3dbccca94b7e08ef7ed4ff6485f52db9c93f4fa209e9a82330bed1981bf99b495c\",\"content_length\":222}],\"upload_attempt_id\":\"<attempt-1>\",\"upload_run_id\":\"<run>\",\"force\":false,\"skip_on_conflict\":true}",+ "status": 201+ }+ ]+}diff --git a/hog/test/parity/golden/e2e/proguard-hash-mismatch.json b/hog/test/parity/golden/e2e/proguard-hash-mismatch.jsonnew file mode 100644index 000000000000..e4392c099fb3--- /dev/null+++ b/hog/test/parity/golden/e2e/proguard-hash-mismatch.json@@ -0,0 +1,64 @@+{+ "exitCode": 1,+ "requests": [+ {+ "method": "GET",+ "path": "/api/projects/1/error_tracking/releases/hash/f5bacd280427e2a06b06ddd5097489794b66ed56bdb85fb8b63a43fca2a2953c45cb348dcf37e252f57d875333b773a1664ade7c5cc02e221eae47b13d3a03d3",+ "headers": {+ "authorization": "Bearer phx_<key>",+ "content-type": "application/json"+ },+ "status": 404+ },+ {+ "method": "POST",+ "path": "/api/projects/1/error_tracking/releases",+ "headers": {+ "authorization": "Bearer phx_<key>",+ "content-type": "application/json"+ },+ "body": "{\"hash_id\":\"f5bacd280427e2a06b06ddd5097489794b66ed56bdb85fb8b63a43fca2a2953c45cb348dcf37e252f57d875333b773a1664ade7c5cc02e221eae47b13d3a03d3\",\"version\":\"1.0+7\",\"project\":\"com.example.app\"}",+ "status": 201+ },+ {+ "method": "POST",+ "path": "/api/projects/1/error_tracking/symbol_sets/bulk_check_upload",+ "headers": {+ "authorization": "Bearer phx_<key>",+ "content-type": "application/json"+ },+ "body": "{\"symbol_sets\":[{\"chunk_id\":\"map-hash-mismatch\",\"release_id\":\"f845c163-4530-518a-9806-6241506198ca\",\"content_hash\":\"72e221661b7a13caab866c5782dc0c99890c67d568fea7d4f9775d7917e1be3dbccca94b7e08ef7ed4ff6485f52db9c93f4fa209e9a82330bed1981bf99b495c\",\"content_length\":222}],\"force\":false,\"skip_on_conflict\":false}",+ "status": 200+ },+ {+ "method": "POST",+ "path": "/api/projects/1/error_tracking/symbol_sets/bulk_start_upload",+ "headers": {+ "authorization": "Bearer phx_<key>",+ "content-type": "application/json"+ },+ "body": "{\"symbol_sets\":[{\"chunk_id\":\"map-hash-mismatch\",\"release_id\":\"f845c163-4530-518a-9806-6241506198ca\",\"content_hash\":\"72e221661b7a13caab866c5782dc0c99890c67d568fea7d4f9775d7917e1be3dbccca94b7e08ef7ed4ff6485f52db9c93f4fa209e9a82330bed1981bf99b495c\",\"content_length\":222}],\"upload_attempt_id\":\"<attempt-1>\",\"upload_run_id\":\"<run>\",\"force\":false,\"skip_on_conflict\":false}",+ "status": 400+ },+ {+ "method": "POST",+ "path": "/api/projects/1/error_tracking/symbol_sets/bulk_start_upload",+ "headers": {+ "authorization": "Bearer phx_<key>",+ "content-type": "application/json"+ },+ "body": "{\"symbol_sets\":[{\"chunk_id\":\"map-hash-mismatch\",\"release_id\":\"f845c163-4530-518a-9806-6241506198ca\",\"content_hash\":\"72e221661b7a13caab866c5782dc0c99890c67d568fea7d4f9775d7917e1be3dbccca94b7e08ef7ed4ff6485f52db9c93f4fa209e9a82330bed1981bf99b495c\",\"content_length\":222}],\"upload_attempt_id\":\"<attempt-1>\",\"upload_run_id\":\"<run>\",\"force\":false,\"skip_on_conflict\":false}",+ "status": 400+ },+ {+ "method": "POST",+ "path": "/api/projects/1/error_tracking/symbol_sets/bulk_start_upload",+ "headers": {+ "authorization": "Bearer phx_<key>",+ "content-type": "application/json"+ },+ "body": "{\"symbol_sets\":[{\"chunk_id\":\"map-hash-mismatch\",\"release_id\":\"f845c163-4530-518a-9806-6241506198ca\",\"content_hash\":\"72e221661b7a13caab866c5782dc0c99890c67d568fea7d4f9775d7917e1be3dbccca94b7e08ef7ed4ff6485f52db9c93f4fa209e9a82330bed1981bf99b495c\",\"content_length\":222}],\"upload_attempt_id\":\"<attempt-1>\",\"upload_run_id\":\"<run>\",\"force\":false,\"skip_on_conflict\":false}",+ "status": 400+ }+ ]+}diff --git a/hog/test/parity/golden/e2e/proguard-no-release.json b/hog/test/parity/golden/e2e/proguard-no-release.jsonnew file mode 100644index 000000000000..32f633409f33--- /dev/null+++ b/hog/test/parity/golden/e2e/proguard-no-release.json@@ -0,0 +1,47 @@+{+ "exitCode": 0,+ "requests": [+ {+ "method": "POST",+ "path": "/api/projects/1/error_tracking/symbol_sets/bulk_check_upload",+ "headers": {+ "authorization": "Bearer phx_<key>",+ "content-type": "application/json"+ },+ "body": "{\"symbol_sets\":[{\"chunk_id\":\"map-no-release\",\"release_id\":null,\"content_hash\":\"72e221661b7a13caab866c5782dc0c99890c67d568fea7d4f9775d7917e1be3dbccca94b7e08ef7ed4ff6485f52db9c93f4fa209e9a82330bed1981bf99b495c\",\"content_length\":222}],\"force\":false,\"skip_on_conflict\":false}",+ "status": 200+ },+ {+ "method": "POST",+ "path": "/api/projects/1/error_tracking/symbol_sets/bulk_start_upload",+ "headers": {+ "authorization": "Bearer phx_<key>",+ "content-type": "application/json"+ },+ "body": "{\"symbol_sets\":[{\"chunk_id\":\"map-no-release\",\"release_id\":null,\"content_hash\":\"72e221661b7a13caab866c5782dc0c99890c67d568fea7d4f9775d7917e1be3dbccca94b7e08ef7ed4ff6485f52db9c93f4fa209e9a82330bed1981bf99b495c\",\"content_length\":222}],\"upload_attempt_id\":\"<attempt-1>\",\"upload_run_id\":\"<run>\",\"force\":false,\"skip_on_conflict\":false}",+ "status": 201+ },+ {+ "method": "PUT",+ "path": "/s3/put/symbolsets/38a0e097-11c0-517d-ba66-3d4e71fe3ad4?length=222",+ "headers": {+ "authorization": "<none>"+ },+ "upload": {+ "sha512": "72e221661b7a13caab866c5782dc0c99890c67d568fea7d4f9775d7917e1be3dbccca94b7e08ef7ed4ff6485f52db9c93f4fa209e9a82330bed1981bf99b495c",+ "length": 222+ },+ "status": 200+ },+ {+ "method": "POST",+ "path": "/api/projects/1/error_tracking/symbol_sets/bulk_finish_upload",+ "headers": {+ "authorization": "Bearer phx_<key>",+ "content-type": "application/json"+ },+ "body": "{\"content_hashes\":{\"38a0e097-11c0-517d-ba66-3d4e71fe3ad4\":\"72e221661b7a13caab866c5782dc0c99890c67d568fea7d4f9775d7917e1be3dbccca94b7e08ef7ed4ff6485f52db9c93f4fa209e9a82330bed1981bf99b495c\"},\"upload_attempt_id\":\"<attempt-1>\",\"upload_run_id\":\"<run>\"}",+ "status": 201+ }+ ]+}diff --git a/hog/test/parity/golden/e2e/proguard-post-only.json b/hog/test/parity/golden/e2e/proguard-post-only.jsonnew file mode 100644index 000000000000..fce697ef6c59--- /dev/null+++ b/hog/test/parity/golden/e2e/proguard-post-only.json@@ -0,0 +1,72 @@+{+ "exitCode": 0,+ "requests": [+ {+ "method": "GET",+ "path": "/api/projects/1/error_tracking/releases/hash/f5bacd280427e2a06b06ddd5097489794b66ed56bdb85fb8b63a43fca2a2953c45cb348dcf37e252f57d875333b773a1664ade7c5cc02e221eae47b13d3a03d3",+ "headers": {+ "authorization": "Bearer phx_<key>",+ "content-type": "application/json"+ },+ "status": 404+ },+ {+ "method": "POST",+ "path": "/api/projects/1/error_tracking/releases",+ "headers": {+ "authorization": "Bearer phx_<key>",+ "content-type": "application/json"+ },+ "body": "{\"hash_id\":\"f5bacd280427e2a06b06ddd5097489794b66ed56bdb85fb8b63a43fca2a2953c45cb348dcf37e252f57d875333b773a1664ade7c5cc02e221eae47b13d3a03d3\",\"version\":\"1.0+7\",\"project\":\"com.example.app\"}",+ "status": 201+ },+ {+ "method": "POST",+ "path": "/api/projects/1/error_tracking/symbol_sets/bulk_check_upload",+ "headers": {+ "authorization": "Bearer phx_<key>",+ "content-type": "application/json"+ },+ "body": "{\"symbol_sets\":[{\"chunk_id\":\"map-post-only\",\"release_id\":\"f845c163-4530-518a-9806-6241506198ca\",\"content_hash\":\"72e221661b7a13caab866c5782dc0c99890c67d568fea7d4f9775d7917e1be3dbccca94b7e08ef7ed4ff6485f52db9c93f4fa209e9a82330bed1981bf99b495c\",\"content_length\":222}],\"force\":false,\"skip_on_conflict\":false}",+ "status": 200+ },+ {+ "method": "POST",+ "path": "/api/projects/1/error_tracking/symbol_sets/bulk_start_upload",+ "headers": {+ "authorization": "Bearer phx_<key>",+ "content-type": "application/json"+ },+ "body": "{\"symbol_sets\":[{\"chunk_id\":\"map-post-only\",\"release_id\":\"f845c163-4530-518a-9806-6241506198ca\",\"content_hash\":\"72e221661b7a13caab866c5782dc0c99890c67d568fea7d4f9775d7917e1be3dbccca94b7e08ef7ed4ff6485f52db9c93f4fa209e9a82330bed1981bf99b495c\",\"content_length\":222}],\"upload_attempt_id\":\"<attempt-1>\",\"upload_run_id\":\"<run>\",\"force\":false,\"skip_on_conflict\":false}",+ "status": 201+ },+ {+ "method": "POST",+ "path": "/s3/post",+ "headers": {+ "authorization": "<none>"+ },+ "upload": {+ "sha512": "72e221661b7a13caab866c5782dc0c99890c67d568fea7d4f9775d7917e1be3dbccca94b7e08ef7ed4ff6485f52db9c93f4fa209e9a82330bed1981bf99b495c",+ "length": 222,+ "fields": {+ "key": "symbolsets/2777305d-1102-5371-a38b-4c5318da5b95",+ "policy": "policy",+ "x-amz-signature": "signature"+ },+ "filename": "file"+ },+ "status": 204+ },+ {+ "method": "POST",+ "path": "/api/projects/1/error_tracking/symbol_sets/bulk_finish_upload",+ "headers": {+ "authorization": "Bearer phx_<key>",+ "content-type": "application/json"+ },+ "body": "{\"content_hashes\":{\"2777305d-1102-5371-a38b-4c5318da5b95\":\"72e221661b7a13caab866c5782dc0c99890c67d568fea7d4f9775d7917e1be3dbccca94b7e08ef7ed4ff6485f52db9c93f4fa209e9a82330bed1981bf99b495c\"},\"upload_attempt_id\":\"<attempt-1>\",\"upload_run_id\":\"<run>\"}",+ "status": 201+ }+ ]+}diff --git a/hog/test/parity/golden/e2e/proguard-release-from-git.json b/hog/test/parity/golden/e2e/proguard-release-from-git.jsonnew file mode 100644index 000000000000..358d797cb1f5--- /dev/null+++ b/hog/test/parity/golden/e2e/proguard-release-from-git.json@@ -0,0 +1,66 @@+{+ "exitCode": 0,+ "requests": [+ {+ "method": "GET",+ "path": "/api/projects/1/error_tracking/releases/hash/1a090dd726e5233c41faaa8e3cdd0d85f295c741f72d295ca5bfac0b9a78d3bb86b23b73148563c49bd81c11d0b8782285a24420156dfddec37f4cb239e4705f",+ "headers": {+ "authorization": "Bearer phx_<key>",+ "content-type": "application/json"+ },+ "status": 404+ },+ {+ "method": "POST",+ "path": "/api/projects/1/error_tracking/releases",+ "headers": {+ "authorization": "Bearer phx_<key>",+ "content-type": "application/json"+ },+ "body": "{\"metadata\":{\"git\":{\"branch\":\"main\",\"commit_id\":\"c0ffee00c0ffee00c0ffee00c0ffee00c0ffee00\",\"remote_url\":\"https://github.com/PostHog/example-app.git\",\"repo_name\":\"example-app\"}},\"hash_id\":\"1a090dd726e5233c41faaa8e3cdd0d85f295c741f72d295ca5bfac0b9a78d3bb86b23b73148563c49bd81c11d0b8782285a24420156dfddec37f4cb239e4705f\",\"version\":\"c0ffee00c0ffee00c0ffee00c0ffee00c0ffee00\",\"project\":\"example-app\"}",+ "status": 201+ },+ {+ "method": "POST",+ "path": "/api/projects/1/error_tracking/symbol_sets/bulk_check_upload",+ "headers": {+ "authorization": "Bearer phx_<key>",+ "content-type": "application/json"+ },+ "body": "{\"symbol_sets\":[{\"chunk_id\":\"map-release-from-git\",\"release_id\":\"36a34f25-35f2-5a0c-9248-4587b214cebe\",\"content_hash\":\"72e221661b7a13caab866c5782dc0c99890c67d568fea7d4f9775d7917e1be3dbccca94b7e08ef7ed4ff6485f52db9c93f4fa209e9a82330bed1981bf99b495c\",\"content_length\":222}],\"force\":false,\"skip_on_conflict\":false}",+ "status": 200+ },+ {+ "method": "POST",+ "path": "/api/projects/1/error_tracking/symbol_sets/bulk_start_upload",+ "headers": {+ "authorization": "Bearer phx_<key>",+ "content-type": "application/json"+ },+ "body": "{\"symbol_sets\":[{\"chunk_id\":\"map-release-from-git\",\"release_id\":\"36a34f25-35f2-5a0c-9248-4587b214cebe\",\"content_hash\":\"72e221661b7a13caab866c5782dc0c99890c67d568fea7d4f9775d7917e1be3dbccca94b7e08ef7ed4ff6485f52db9c93f4fa209e9a82330bed1981bf99b495c\",\"content_length\":222}],\"upload_attempt_id\":\"<attempt-1>\",\"upload_run_id\":\"<run>\",\"force\":false,\"skip_on_conflict\":false}",+ "status": 201+ },+ {+ "method": "PUT",+ "path": "/s3/put/symbolsets/0d737a1b-88b1-510c-8dbb-7a58a4f72db6?length=222",+ "headers": {+ "authorization": "<none>"+ },+ "upload": {+ "sha512": "72e221661b7a13caab866c5782dc0c99890c67d568fea7d4f9775d7917e1be3dbccca94b7e08ef7ed4ff6485f52db9c93f4fa209e9a82330bed1981bf99b495c",+ "length": 222+ },+ "status": 200+ },+ {+ "method": "POST",+ "path": "/api/projects/1/error_tracking/symbol_sets/bulk_finish_upload",+ "headers": {+ "authorization": "Bearer phx_<key>",+ "content-type": "application/json"+ },+ "body": "{\"content_hashes\":{\"0d737a1b-88b1-510c-8dbb-7a58a4f72db6\":\"72e221661b7a13caab866c5782dc0c99890c67d568fea7d4f9775d7917e1be3dbccca94b7e08ef7ed4ff6485f52db9c93f4fa209e9a82330bed1981bf99b495c\"},\"upload_attempt_id\":\"<attempt-1>\",\"upload_run_id\":\"<run>\"}",+ "status": 201+ }+ ]+}diff --git a/hog/test/parity/golden/e2e/proguard-release-mismatch.json b/hog/test/parity/golden/e2e/proguard-release-mismatch.jsonnew file mode 100644index 000000000000..dbba2923252b--- /dev/null+++ b/hog/test/parity/golden/e2e/proguard-release-mismatch.json@@ -0,0 +1,106 @@+{+ "exitCode": 0,+ "requests": [+ {+ "method": "GET",+ "path": "/api/projects/1/error_tracking/releases/hash/f5bacd280427e2a06b06ddd5097489794b66ed56bdb85fb8b63a43fca2a2953c45cb348dcf37e252f57d875333b773a1664ade7c5cc02e221eae47b13d3a03d3",+ "headers": {+ "authorization": "Bearer phx_<key>",+ "content-type": "application/json"+ },+ "status": 404+ },+ {+ "method": "POST",+ "path": "/api/projects/1/error_tracking/releases",+ "headers": {+ "authorization": "Bearer phx_<key>",+ "content-type": "application/json"+ },+ "body": "{\"hash_id\":\"f5bacd280427e2a06b06ddd5097489794b66ed56bdb85fb8b63a43fca2a2953c45cb348dcf37e252f57d875333b773a1664ade7c5cc02e221eae47b13d3a03d3\",\"version\":\"1.0+7\",\"project\":\"com.example.app\"}",+ "status": 201+ },+ {+ "method": "POST",+ "path": "/api/projects/1/error_tracking/symbol_sets/bulk_check_upload",+ "headers": {+ "authorization": "Bearer phx_<key>",+ "content-type": "application/json"+ },+ "body": "{\"symbol_sets\":[{\"chunk_id\":\"map-release-mismatch\",\"release_id\":\"f845c163-4530-518a-9806-6241506198ca\",\"content_hash\":\"72e221661b7a13caab866c5782dc0c99890c67d568fea7d4f9775d7917e1be3dbccca94b7e08ef7ed4ff6485f52db9c93f4fa209e9a82330bed1981bf99b495c\",\"content_length\":222}],\"force\":false,\"skip_on_conflict\":false}",+ "status": 200+ },+ {+ "method": "POST",+ "path": "/api/projects/1/error_tracking/symbol_sets/bulk_start_upload",+ "headers": {+ "authorization": "Bearer phx_<key>",+ "content-type": "application/json"+ },+ "body": "{\"symbol_sets\":[{\"chunk_id\":\"map-release-mismatch\",\"release_id\":\"f845c163-4530-518a-9806-6241506198ca\",\"content_hash\":\"72e221661b7a13caab866c5782dc0c99890c67d568fea7d4f9775d7917e1be3dbccca94b7e08ef7ed4ff6485f52db9c93f4fa209e9a82330bed1981bf99b495c\",\"content_length\":222}],\"upload_attempt_id\":\"<attempt-1>\",\"upload_run_id\":\"<run>\",\"force\":false,\"skip_on_conflict\":false}",+ "status": 400+ },+ {+ "method": "POST",+ "path": "/api/projects/1/error_tracking/symbol_sets/bulk_start_upload",+ "headers": {+ "authorization": "Bearer phx_<key>",+ "content-type": "application/json"+ },+ "body": "{\"symbol_sets\":[{\"chunk_id\":\"map-release-mismatch\",\"release_id\":\"f845c163-4530-518a-9806-6241506198ca\",\"content_hash\":\"72e221661b7a13caab866c5782dc0c99890c67d568fea7d4f9775d7917e1be3dbccca94b7e08ef7ed4ff6485f52db9c93f4fa209e9a82330bed1981bf99b495c\",\"content_length\":222}],\"upload_attempt_id\":\"<attempt-1>\",\"upload_run_id\":\"<run>\",\"force\":false,\"skip_on_conflict\":false}",+ "status": 400+ },+ {+ "method": "POST",+ "path": "/api/projects/1/error_tracking/symbol_sets/bulk_start_upload",+ "headers": {+ "authorization": "Bearer phx_<key>",+ "content-type": "application/json"+ },+ "body": "{\"symbol_sets\":[{\"chunk_id\":\"map-release-mismatch\",\"release_id\":\"f845c163-4530-518a-9806-6241506198ca\",\"content_hash\":\"72e221661b7a13caab866c5782dc0c99890c67d568fea7d4f9775d7917e1be3dbccca94b7e08ef7ed4ff6485f52db9c93f4fa209e9a82330bed1981bf99b495c\",\"content_length\":222}],\"upload_attempt_id\":\"<attempt-1>\",\"upload_run_id\":\"<run>\",\"force\":false,\"skip_on_conflict\":false}",+ "status": 400+ },+ {+ "method": "POST",+ "path": "/api/projects/1/error_tracking/symbol_sets/bulk_check_upload",+ "headers": {+ "authorization": "Bearer phx_<key>",+ "content-type": "application/json"+ },+ "body": "{\"symbol_sets\":[{\"chunk_id\":\"map-release-mismatch\",\"release_id\":null,\"content_hash\":\"72e221661b7a13caab866c5782dc0c99890c67d568fea7d4f9775d7917e1be3dbccca94b7e08ef7ed4ff6485f52db9c93f4fa209e9a82330bed1981bf99b495c\",\"content_length\":222}],\"force\":false,\"skip_on_conflict\":false}",+ "status": 200+ },+ {+ "method": "POST",+ "path": "/api/projects/1/error_tracking/symbol_sets/bulk_start_upload",+ "headers": {+ "authorization": "Bearer phx_<key>",+ "content-type": "application/json"+ },+ "body": "{\"symbol_sets\":[{\"chunk_id\":\"map-release-mismatch\",\"release_id\":null,\"content_hash\":\"72e221661b7a13caab866c5782dc0c99890c67d568fea7d4f9775d7917e1be3dbccca94b7e08ef7ed4ff6485f52db9c93f4fa209e9a82330bed1981bf99b495c\",\"content_length\":222}],\"upload_attempt_id\":\"<attempt-2>\",\"upload_run_id\":\"<run>\",\"force\":false,\"skip_on_conflict\":false}",+ "status": 201+ },+ {+ "method": "PUT",+ "path": "/s3/put/symbolsets/05c0cf62-91da-51c9-9d41-3e87cb097b97?length=222",+ "headers": {+ "authorization": "<none>"+ },+ "upload": {+ "sha512": "72e221661b7a13caab866c5782dc0c99890c67d568fea7d4f9775d7917e1be3dbccca94b7e08ef7ed4ff6485f52db9c93f4fa209e9a82330bed1981bf99b495c",+ "length": 222+ },+ "status": 200+ },+ {+ "method": "POST",+ "path": "/api/projects/1/error_tracking/symbol_sets/bulk_finish_upload",+ "headers": {+ "authorization": "Bearer phx_<key>",+ "content-type": "application/json"+ },+ "body": "{\"content_hashes\":{\"05c0cf62-91da-51c9-9d41-3e87cb097b97\":\"72e221661b7a13caab866c5782dc0c99890c67d568fea7d4f9775d7917e1be3dbccca94b7e08ef7ed4ff6485f52db9c93f4fa209e9a82330bed1981bf99b495c\"},\"upload_attempt_id\":\"<attempt-2>\",\"upload_run_id\":\"<run>\"}",+ "status": 201+ }+ ]+}diff --git a/hog/test/parity/golden/e2e/proguard-start-500-once.json b/hog/test/parity/golden/e2e/proguard-start-500-once.jsonnew file mode 100644index 000000000000..e86daf590a85--- /dev/null+++ b/hog/test/parity/golden/e2e/proguard-start-500-once.json@@ -0,0 +1,76 @@+{+ "exitCode": 0,+ "requests": [+ {+ "method": "GET",+ "path": "/api/projects/1/error_tracking/releases/hash/f5bacd280427e2a06b06ddd5097489794b66ed56bdb85fb8b63a43fca2a2953c45cb348dcf37e252f57d875333b773a1664ade7c5cc02e221eae47b13d3a03d3",+ "headers": {+ "authorization": "Bearer phx_<key>",+ "content-type": "application/json"+ },+ "status": 404+ },+ {+ "method": "POST",+ "path": "/api/projects/1/error_tracking/releases",+ "headers": {+ "authorization": "Bearer phx_<key>",+ "content-type": "application/json"+ },+ "body": "{\"hash_id\":\"f5bacd280427e2a06b06ddd5097489794b66ed56bdb85fb8b63a43fca2a2953c45cb348dcf37e252f57d875333b773a1664ade7c5cc02e221eae47b13d3a03d3\",\"version\":\"1.0+7\",\"project\":\"com.example.app\"}",+ "status": 201+ },+ {+ "method": "POST",+ "path": "/api/projects/1/error_tracking/symbol_sets/bulk_check_upload",+ "headers": {+ "authorization": "Bearer phx_<key>",+ "content-type": "application/json"+ },+ "body": "{\"symbol_sets\":[{\"chunk_id\":\"map-start-500-once\",\"release_id\":\"f845c163-4530-518a-9806-6241506198ca\",\"content_hash\":\"72e221661b7a13caab866c5782dc0c99890c67d568fea7d4f9775d7917e1be3dbccca94b7e08ef7ed4ff6485f52db9c93f4fa209e9a82330bed1981bf99b495c\",\"content_length\":222}],\"force\":false,\"skip_on_conflict\":false}",+ "status": 200+ },+ {+ "method": "POST",+ "path": "/api/projects/1/error_tracking/symbol_sets/bulk_start_upload",+ "headers": {+ "authorization": "Bearer phx_<key>",+ "content-type": "application/json"+ },+ "body": "{\"symbol_sets\":[{\"chunk_id\":\"map-start-500-once\",\"release_id\":\"f845c163-4530-518a-9806-6241506198ca\",\"content_hash\":\"72e221661b7a13caab866c5782dc0c99890c67d568fea7d4f9775d7917e1be3dbccca94b7e08ef7ed4ff6485f52db9c93f4fa209e9a82330bed1981bf99b495c\",\"content_length\":222}],\"upload_attempt_id\":\"<attempt-1>\",\"upload_run_id\":\"<run>\",\"force\":false,\"skip_on_conflict\":false}",+ "status": 500+ },+ {+ "method": "POST",+ "path": "/api/projects/1/error_tracking/symbol_sets/bulk_start_upload",+ "headers": {+ "authorization": "Bearer phx_<key>",+ "content-type": "application/json"+ },+ "body": "{\"symbol_sets\":[{\"chunk_id\":\"map-start-500-once\",\"release_id\":\"f845c163-4530-518a-9806-6241506198ca\",\"content_hash\":\"72e221661b7a13caab866c5782dc0c99890c67d568fea7d4f9775d7917e1be3dbccca94b7e08ef7ed4ff6485f52db9c93f4fa209e9a82330bed1981bf99b495c\",\"content_length\":222}],\"upload_attempt_id\":\"<attempt-1>\",\"upload_run_id\":\"<run>\",\"force\":false,\"skip_on_conflict\":false}",+ "status": 201+ },+ {+ "method": "PUT",+ "path": "/s3/put/symbolsets/a4fe8f3f-afc1-55f2-8a06-b947ec3000b6?length=222",+ "headers": {+ "authorization": "<none>"+ },+ "upload": {+ "sha512": "72e221661b7a13caab866c5782dc0c99890c67d568fea7d4f9775d7917e1be3dbccca94b7e08ef7ed4ff6485f52db9c93f4fa209e9a82330bed1981bf99b495c",+ "length": 222+ },+ "status": 200+ },+ {+ "method": "POST",+ "path": "/api/projects/1/error_tracking/symbol_sets/bulk_finish_upload",+ "headers": {+ "authorization": "Bearer phx_<key>",+ "content-type": "application/json"+ },+ "body": "{\"content_hashes\":{\"a4fe8f3f-afc1-55f2-8a06-b947ec3000b6\":\"72e221661b7a13caab866c5782dc0c99890c67d568fea7d4f9775d7917e1be3dbccca94b7e08ef7ed4ff6485f52db9c93f4fa209e9a82330bed1981bf99b495c\"},\"upload_attempt_id\":\"<attempt-1>\",\"upload_run_id\":\"<run>\"}",+ "status": 201+ }+ ]+}diff --git a/hog/test/parity/inputs.ts b/hog/test/parity/inputs.tsnew file mode 100644index 000000000000..4b28b0e89d3f--- /dev/null+++ b/hog/test/parity/inputs.ts@@ -0,0 +1,51 @@+// Deterministic inputs for parity goldens. The recorder and the tests generate the same bytes from+// (generator, seed, size), so large inputs never need to be checked in.+export type Generator = 'ascii' | 'lines' | 'bytes'++export interface InputSpec {+ generator: Generator+ seed: number+ size: number+}++// xorshift32: tiny, fast and identical everywhere.+function random(seed: number): () => number {+ let state = seed >>> 0 || 1+ return () => {+ state ^= state << 13+ state >>>= 0+ state ^= state >>> 17+ state ^= state << 5+ state >>>= 0+ return state+ }+}++const LINE_WORDS = ['com.example.app.Model', 'getValue', 'setValue', 'onCreate', 'java.lang.String', 'int', 'void']++export function generateInput({ generator, seed, size }: InputSpec): Uint8Array {+ const next = random(seed)+ const out = new Uint8Array(size)+ if (generator === 'bytes') {+ for (let index = 0; index < size; index++) {+ out[index] = next() & 0xff+ }+ return out+ }+ if (generator === 'ascii') {+ for (let index = 0; index < size; index++) {+ out[index] = 32 + (next() % 95)+ }+ return out+ }+ // `lines`: ProGuard-like text, so compression finds long repeats like a real mapping.+ let index = 0+ while (index < size) {+ const word = LINE_WORDS[next() % LINE_WORDS.length]!+ const line = ` ${next() % 900}:${next() % 900}:${word} ${word}(${next() % 7}) -> ${String.fromCharCode(97 + (next() % 26))}\n`+ for (let char = 0; char < line.length && index < size; char++) {+ out[index++] = line.charCodeAt(char)+ }+ }+ return out+}diff --git a/hog/test/parity/normalize.ts b/hog/test/parity/normalize.tsnew file mode 100644index 000000000000..0ec9809eb955--- /dev/null+++ b/hog/test/parity/normalize.ts@@ -0,0 +1,81 @@+import type { RecordedRequest } from './fake-server'++// Rewrites only what is random by design, so the rest can be compared byte for byte:+// - upload run and attempt ids (UUIDv7) become <run> and <attempt-n>,+// - the keys of `content_hashes` and release `metadata`, which Rust writes in HashMap order, are sorted,+// - object-storage uploads inside one batch are sorted by path, because they run in parallel,+// - the multipart boundary, the user agent and object-storage headers are dropped.+// The user agent differs on purpose: hog sends `hog/<version>`, posthog-cli sends `posthog-cli`.+export interface NormalizedRequest {+ method: string+ path: string+ headers: Record<string, string>+ body?: string+ upload?: RecordedRequest['upload']+ status: number+}++function sortKeys(object: Record<string, unknown>): Record<string, unknown> {+ return Object.fromEntries(+ Object.keys(object)+ .sort()+ .map((key) => [key, object[key]])+ )+}++export function normalize(requests: RecordedRequest[]): NormalizedRequest[] {+ const attempts = new Map<string, string>()+ const out: NormalizedRequest[] = requests.map((request) => {+ const isStorage = request.path.startsWith('/s3/')+ const headers: Record<string, string> = isStorage+ ? { authorization: request.headers.authorization ?? '<none>' }+ : {+ authorization: request.headers.authorization ?? '<none>',+ 'content-type': (request.headers['content-type'] ?? '<none>').replace(/;\s*boundary=.*/, ''),+ }+ let body = request.body+ if (body) {+ const parsed = JSON.parse(body) as Record<string, unknown>+ if ('upload_run_id' in parsed) {+ parsed.upload_run_id = '<run>'+ }+ if (typeof parsed.upload_attempt_id === 'string') {+ if (!attempts.has(parsed.upload_attempt_id)) {+ attempts.set(parsed.upload_attempt_id, `<attempt-${attempts.size + 1}>`)+ }+ parsed.upload_attempt_id = attempts.get(parsed.upload_attempt_id)+ }+ if (parsed.content_hashes && typeof parsed.content_hashes === 'object') {+ parsed.content_hashes = sortKeys(parsed.content_hashes as Record<string, unknown>)+ }+ if (parsed.metadata && typeof parsed.metadata === 'object') {+ parsed.metadata = sortKeys(parsed.metadata as Record<string, unknown>)+ }+ body = JSON.stringify(parsed)+ }+ const upload = request.upload && {+ ...request.upload,+ fields: request.upload.fields && (sortKeys(request.upload.fields) as Record<string, string>),+ }+ return {+ method: request.method,+ path: request.path,+ headers,+ ...(body ? { body } : {}),+ ...(upload ? { upload } : {}),+ status: request.status,+ }+ })+ for (let start = 0; start < out.length; start++) {+ if (!out[start]!.path.startsWith('/s3/')) {+ continue+ }+ let end = start+ while (end < out.length && out[end]!.path.startsWith('/s3/')) {+ end+++ }+ out.splice(start, end - start, ...out.slice(start, end).sort((a, b) => (a.path < b.path ? -1 : 1)))+ start = end+ }+ return out+}diff --git a/hog/test/parity/record-containers.ts b/hog/test/parity/record-containers.tsnew file mode 100644index 000000000000..e937bbc06742--- /dev/null+++ b/hog/test/parity/record-containers.ts@@ -0,0 +1,26 @@+// Records container goldens from the Rust oracle. Run from hog/ after building the oracle:+// (cd ../cli && cargo build --release --example hog_parity_oracle)+// bun test/parity/record-containers.ts <path to hog_parity_oracle>+import { mkdtempSync, writeFileSync } from 'node:fs'+import { tmpdir } from 'node:os'+import { join } from 'node:path'++import { CONTAINER_CASES } from './containers'+import { generateInput } from './inputs'++const oracle = process.argv[2]+if (!oracle) {+ throw new Error('Pass the path to the hog_parity_oracle binary.')+}+const folder = mkdtempSync(join(tmpdir(), 'hog-parity-'))+const golden = CONTAINER_CASES.map((testCase) => {+ const file = join(folder, 'input')+ writeFileSync(file, generateInput(testCase.input))+ const result = Bun.spawnSync([oracle, 'container', testCase.type, file])+ if (result.exitCode !== 0) {+ throw new Error(`oracle failed for ${JSON.stringify(testCase)}: ${result.stderr.toString()}`)+ }+ return { ...testCase, hash: result.stdout.toString().trim() }+})+writeFileSync(join(import.meta.dir, 'golden', 'containers.json'), `${JSON.stringify(golden, null, 2)}\n`)+process.stdout.write(`Recorded ${golden.length} container goldens.\n`)diff --git a/hog/test/parity/record-e2e.ts b/hog/test/parity/record-e2e.tsnew file mode 100644index 000000000000..4cbdad088d9d--- /dev/null+++ b/hog/test/parity/record-e2e.ts@@ -0,0 +1,20 @@+// Records end-to-end goldens by running posthog-cli against the fake server. Run from hog/:+// (cd ../cli && cargo build --release)+// bun test/parity/record-e2e.ts <path to posthog-cli> [scenario name...]+import { mkdirSync, writeFileSync } from 'node:fs'+import { join } from 'node:path'++import { runScenario } from './run'+import { SCENARIOS } from './scenarios'++const [binary, ...only] = process.argv.slice(2)+if (!binary) {+ throw new Error('Pass the path to a posthog-cli binary built with `cargo build --release`.')+}+const folder = join(import.meta.dir, 'golden', 'e2e')+mkdirSync(folder, { recursive: true })+for (const scenario of SCENARIOS.filter((candidate) => only.length === 0 || only.includes(candidate.name))) {+ const result = await runScenario(scenario, { rust: binary })+ writeFileSync(join(folder, `${scenario.name}.json`), `${JSON.stringify(result, null, 2)}\n`)+ process.stdout.write(`${scenario.name}: exit ${result.exitCode}, ${result.requests.length} requests\n`)+}diff --git a/hog/test/parity/run.ts b/hog/test/parity/run.tsnew file mode 100644index 000000000000..303edc48decf--- /dev/null+++ b/hog/test/parity/run.ts@@ -0,0 +1,69 @@+import { mkdtempSync, rmSync } from 'node:fs'+import { tmpdir } from 'node:os'+import { join } from 'node:path'++import { run } from '@/cli'+import { processRuntime } from '@/core/runtime'++import { startFakeServer } from './fake-server'+import { write } from './fixtures'+import { normalize, type NormalizedRequest } from './normalize'+import type { ParityScenario } from './scenarios'++export interface ParityResult {+ exitCode: number+ requests: NormalizedRequest[]+}++function environment(serverUrl: string, home: string): Record<string, string> {+ return {+ HOME: home,+ POSTHOG_HOME: home,+ POSTHOG_CLI_API_KEY: 'phx_parity',+ POSTHOG_CLI_PROJECT_ID: '1',+ POSTHOG_CLI_HOST: serverUrl,+ NO_COLOR: '1',+ }+}++export async function runScenario(scenario: ParityScenario, cli: { rust: string } | 'hog'): Promise<ParityResult> {+ const folder = mkdtempSync(join(tmpdir(), 'hog-parity-'))+ const home = mkdtempSync(join(tmpdir(), 'hog-parity-home-'))+ write(folder, scenario.files)+ const server = startFakeServer(scenario.server)+ try {+ let exitCode = 0+ for (let index = 0; index < (scenario.runs ?? 1); index++) {+ server.requests.length = 0+ const env = environment(server.url, home)+ if (cli === 'hog') {+ const runtime = {+ ...processRuntime(),+ env,+ cwd: () => folder,+ stdinIsTTY: false,+ stdoutIsTTY: false,+ stdoutHasColors: false,+ writeStdout: () => {},+ writeStderr: () => {},+ // Retry delays don't change what is sent, so tests skip them.+ sleep: async () => {},+ }+ exitCode = await run(scenario.hog, runtime)+ } else {+ const child = Bun.spawn([cli.rust, ...scenario.rust], {+ cwd: folder,+ env: { PATH: process.env.PATH ?? '', ...env },+ stdout: 'pipe',+ stderr: 'pipe',+ })+ exitCode = await child.exited+ }+ }+ return { exitCode, requests: normalize(server.requests) }+ } finally {+ server.stop()+ rmSync(folder, { recursive: true, force: true })+ rmSync(home, { recursive: true, force: true })+ }+}diff --git a/hog/test/parity/scenarios.ts b/hog/test/parity/scenarios.tsnew file mode 100644index 000000000000..d044c10d1105--- /dev/null+++ b/hog/test/parity/scenarios.ts@@ -0,0 +1,50 @@+import type { Scenario } from './fake-server'+import { GIT_REPO, mappingOfSize, SMALL_MAPPING } from './fixtures'++export interface ParityScenario {+ name: string+ server: Scenario+ files: Record<string, string | Uint8Array>+ rust: string[]+ hog: string[]+ // Run this many times against the same server and compare only the last run, to cover re-uploads.+ runs?: number+}++const release = ['--release-name', 'com.example.app', '--release-version', '1.0', '--build', '7']++const proguard = (+ name: string,+ server: Scenario,+ options: Partial<ParityScenario> & { args?: string[]; file?: string } = {}+): ParityScenario => {+ const file = options.file ?? 'mapping.txt'+ const args = options.args ?? []+ return {+ name: `proguard-${name}`,+ server,+ files: options.files ?? { [file]: SMALL_MAPPING },+ rust: ['proguard', 'upload', '--path', file, '--map-id', `map-${name}`, ...args],+ hog: ['error-tracking', 'upload', file, '--map-id', `map-${name}`, ...args],+ runs: options.runs,+ }+}++export const SCENARIOS: ParityScenario[] = [+ proguard('fresh', 'fresh', { args: release }),+ proguard('no-release', 'fresh'),+ proguard('release-from-git', 'fresh', {+ file: 'app/mapping.txt',+ files: { ...GIT_REPO, 'app/mapping.txt': SMALL_MAPPING },+ }),+ proguard('already-present', 'fresh', { args: release, runs: 2 }),+ proguard('post-only', 'post-only', { args: release }),+ proguard('hash-mismatch', 'hash-mismatch', { args: release }),+ proguard('hash-mismatch-force', 'hash-mismatch', { args: [...release, '--force'] }),+ proguard('hash-mismatch-skip', 'hash-mismatch', { args: [...release, '--skip-on-conflict'] }),+ proguard('release-mismatch', 'release-mismatch', { args: release }),+ proguard('check-403', 'check-403', { args: release }),+ proguard('start-500-once', 'start-500-once', { args: release }),+ proguard('block-multiple', 'fresh', { files: { 'mapping.txt': mappingOfSize(2 * 128 * 1024) } }),+ proguard('bom-crlf', 'fresh', { files: { 'mapping.txt': `${SMALL_MAPPING.replaceAll('\n', '\r\n')}` } }),+]diff --git a/hog/tsconfig.json b/hog/tsconfig.jsonindex 3dc843e43b65..6357cb74203b 100644--- a/hog/tsconfig.json+++ b/hog/tsconfig.json@@ -14,5 +14,5 @@"@/*": ["./src/*"]}},- "include": ["src"]+ "include": ["src", "test", "scripts"]}diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 6d0ba1211e73..0f33b97850e3 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -1529,6 +1529,9 @@ importers:commander:specifier: 15.0.0version: 15.0.0+ zod:+ specifier: ^4.3.6+ version: 4.3.6devDependencies:'@types/bun':specifier: 1.3.14