Skip to content

: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.

chore(wizard): snapshot cloud worker commands (#97061)

Fernando Gomes68c7ba41199c
diff --git a/products/wizard/backend/tests/runs/__snapshots__/test_wizard_command/test_wizard_command[audit-eu].txt b/products/wizard/backend/tests/runs/__snapshots__/test_wizard_command/test_wizard_command[audit-eu].txt
new file mode 100644
index 000000000000..fe97e63e80fe
--- /dev/null
+++ b/products/wizard/backend/tests/runs/__snapshots__/test_wizard_command/test_wizard_command[audit-eu].txt
@@ -0,0 +1,10 @@
+timeout -k 30 2700 sh -c 'rm -rf /tmp/posthog-wizard-package && mkdir -p /tmp/posthog-wizard-package && rm -f /tmp/posthog-wizard-global.npmrc && touch /tmp/posthog-wizard-global.npmrc && npm --userconfig=/dev/null --globalconfig=/tmp/posthog-wizard-global.npmrc install --ignore-scripts --no-package-lock --no-save --prefix /tmp/posthog-wizard-package --registry=https://registry.npmjs.org @posthog/[email protected] && cd '"'"'/workspace/example user'"'"'"'"'"'"'"'"'s project'"'"' && node /tmp/posthog-wizard-package/node_modules/@posthog/wizard/dist/bin.js audit web-analytics --headless-DONOTUSE-EXPERIMENTAL --install-dir . --region eu --project-id 7'
+
+Shell script:
+rm -rf /tmp/posthog-wizard-package
+mkdir -p /tmp/posthog-wizard-package
+rm -f /tmp/posthog-wizard-global.npmrc
+touch /tmp/posthog-wizard-global.npmrc
+npm --userconfig=/dev/null --globalconfig=/tmp/posthog-wizard-global.npmrc install --ignore-scripts --no-package-lock --no-save --prefix /tmp/posthog-wizard-package --registry=https://registry.npmjs.org @posthog/[email protected]
+cd '/workspace/example user'"'"'s project'
+node /tmp/posthog-wizard-package/node_modules/@posthog/wizard/dist/bin.js audit web-analytics --headless-DONOTUSE-EXPERIMENTAL --install-dir . --region eu --project-id 7
diff --git a/products/wizard/backend/tests/runs/__snapshots__/test_wizard_command/test_wizard_command[debug-local].txt b/products/wizard/backend/tests/runs/__snapshots__/test_wizard_command/test_wizard_command[debug-local].txt
new file mode 100644
index 000000000000..500542b12b1c
--- /dev/null
+++ b/products/wizard/backend/tests/runs/__snapshots__/test_wizard_command/test_wizard_command[debug-local].txt
@@ -0,0 +1,5 @@
+timeout -k 30 2700 sh -c 'cd '"'"'/workspace/example user'"'"'"'"'"'"'"'"'s project'"'"' && node /tmp/posthog-local-wizard/dist/bin.js audit web-analytics --headless-DONOTUSE-EXPERIMENTAL --install-dir . --region eu --project-id 7 --base-url "$POSTHOG_API_URL"'
+
+Shell script:
+cd '/workspace/example user'"'"'s project'
+node /tmp/posthog-local-wizard/dist/bin.js audit web-analytics --headless-DONOTUSE-EXPERIMENTAL --install-dir . --region eu --project-id 7 --base-url "$POSTHOG_API_URL"
diff --git a/products/wizard/backend/tests/runs/__snapshots__/test_wizard_command/test_wizard_command[debug-package].txt b/products/wizard/backend/tests/runs/__snapshots__/test_wizard_command/test_wizard_command[debug-package].txt
new file mode 100644
index 000000000000..2b279d79b39f
--- /dev/null
+++ b/products/wizard/backend/tests/runs/__snapshots__/test_wizard_command/test_wizard_command[debug-package].txt
@@ -0,0 +1,10 @@
+timeout -k 30 2700 sh -c 'rm -rf /tmp/posthog-wizard-package && mkdir -p /tmp/posthog-wizard-package && rm -f /tmp/posthog-wizard-global.npmrc && touch /tmp/posthog-wizard-global.npmrc && npm --userconfig=/dev/null --globalconfig=/tmp/posthog-wizard-global.npmrc install --ignore-scripts --no-package-lock --no-save --prefix /tmp/posthog-wizard-package --registry=https://registry.npmjs.org @posthog/[email protected] && cd '"'"'/workspace/example user'"'"'"'"'"'"'"'"'s project'"'"' && node /tmp/posthog-wizard-package/node_modules/@posthog/wizard/dist/bin.js --headless-DONOTUSE-EXPERIMENTAL --install-dir . --region us --project-id 7 --base-url "$POSTHOG_API_URL"'
+
+Shell script:
+rm -rf /tmp/posthog-wizard-package
+mkdir -p /tmp/posthog-wizard-package
+rm -f /tmp/posthog-wizard-global.npmrc
+touch /tmp/posthog-wizard-global.npmrc
+npm --userconfig=/dev/null --globalconfig=/tmp/posthog-wizard-global.npmrc install --ignore-scripts --no-package-lock --no-save --prefix /tmp/posthog-wizard-package --registry=https://registry.npmjs.org @posthog/[email protected]
+cd '/workspace/example user'"'"'s project'
+node /tmp/posthog-wizard-package/node_modules/@posthog/wizard/dist/bin.js --headless-DONOTUSE-EXPERIMENTAL --install-dir . --region us --project-id 7 --base-url "$POSTHOG_API_URL"
diff --git a/products/wizard/backend/tests/runs/__snapshots__/test_wizard_command/test_wizard_command[default-us].txt b/products/wizard/backend/tests/runs/__snapshots__/test_wizard_command/test_wizard_command[default-us].txt
new file mode 100644
index 000000000000..d10b87362d98
--- /dev/null
+++ b/products/wizard/backend/tests/runs/__snapshots__/test_wizard_command/test_wizard_command[default-us].txt
@@ -0,0 +1,10 @@
+timeout -k 30 2700 sh -c 'rm -rf /tmp/posthog-wizard-package && mkdir -p /tmp/posthog-wizard-package && rm -f /tmp/posthog-wizard-global.npmrc && touch /tmp/posthog-wizard-global.npmrc && npm --userconfig=/dev/null --globalconfig=/tmp/posthog-wizard-global.npmrc install --ignore-scripts --no-package-lock --no-save --prefix /tmp/posthog-wizard-package --registry=https://registry.npmjs.org @posthog/[email protected] && cd '"'"'/workspace/example user'"'"'"'"'"'"'"'"'s project'"'"' && node /tmp/posthog-wizard-package/node_modules/@posthog/wizard/dist/bin.js --headless-DONOTUSE-EXPERIMENTAL --install-dir . --region us --project-id 7'
+
+Shell script:
+rm -rf /tmp/posthog-wizard-package
+mkdir -p /tmp/posthog-wizard-package
+rm -f /tmp/posthog-wizard-global.npmrc
+touch /tmp/posthog-wizard-global.npmrc
+npm --userconfig=/dev/null --globalconfig=/tmp/posthog-wizard-global.npmrc install --ignore-scripts --no-package-lock --no-save --prefix /tmp/posthog-wizard-package --registry=https://registry.npmjs.org @posthog/[email protected]
+cd '/workspace/example user'"'"'s project'
+node /tmp/posthog-wizard-package/node_modules/@posthog/wizard/dist/bin.js --headless-DONOTUSE-EXPERIMENTAL --install-dir . --region us --project-id 7
diff --git a/products/wizard/backend/tests/runs/test_wizard_command.py b/products/wizard/backend/tests/runs/test_wizard_command.py
new file mode 100644
index 000000000000..da3d6fb22151
--- /dev/null
+++ b/products/wizard/backend/tests/runs/test_wizard_command.py
@@ -0,0 +1,49 @@
+import shlex
+
+import pytest
+from unittest.mock import patch
+
+from django.test import override_settings
+
+from syrupy.assertion import SnapshotAssertion
+from syrupy.extensions.single_file import SingleFileSnapshotExtension, WriteMode
+
+from products.wizard.backend.logic.workers.commands import build_wizard_command
+
+
+class CommandSnapshotExtension(SingleFileSnapshotExtension):
+ _file_extension = "txt"
+ _write_mode = WriteMode.TEXT
+
+
+ "region,debug,use_local_wizard_source,program_command",
+ [
+ pytest.param("US", False, False, (), id="default-us"),
+ pytest.param("EU", False, False, ("audit", "web-analytics"), id="audit-eu"),
+ pytest.param("US", True, False, (), id="debug-package"),
+ pytest.param("EU", True, True, ("audit", "web-analytics"), id="debug-local"),
+ ],
+)
+def test_wizard_command(
+ snapshot: SnapshotAssertion,
+ region: str,
+ debug: bool,
+ use_local_wizard_source: bool,
+ program_command: tuple[str, ...],
+) -> None:
+ with (
+ override_settings(DEBUG=debug),
+ patch("products.wizard.backend.logic.workers.commands.get_instance_region", return_value=region),
+ ):
+ command = build_wizard_command(
+ "/workspace/example user's project",
+ 7,
+ "2.67.0",
+ program_command,
+ use_local_wizard_source=use_local_wizard_source,
+ )
+
+ script = shlex.split(command)[-1]
+ readable_script = script.replace(" && ", "\n")
+ assert f"{command}\n\nShell script:\n{readable_script}\n" == snapshot(extension_class=CommandSnapshotExtension)