Skip to content

Conversation

@lukaskratzel
Copy link
Contributor

@lukaskratzel lukaskratzel commented Dec 1, 2025

Description

This PR introduces a strategy pattern to load theia environment variables supporting the following strategies:

  • ProcessEnvStrategy (default): Loads environment variables from the process environment. Functionally equivalent to the strategy used before this PR
  • DataBridgeStrategy (Used if the process environment variable SCORPIO_THEIA_ENV_STRATEGY is 'data-bridge'). Uses the data bridge VSCode extension to load environment variables dynamically at runtime. This allows the scorpio extension to wait until the required environment variables become available externally. This work is important to support scorpio in theia environments that are prewarmed. This strategy uses a separate output channel for observability.

Steps for Testing

Testing all possible cases is tricky. Here's how I did it using a helper bash script as seen below.

  1. Build scorpio and data-bridge extension locally
  2. Mount the extensions into one of our theia images (allows fast iterations without rebuild)
  3. Test all scenarios using this setup

Relevant scenarios

  1. Scorpio in VSCode, using the default strategy
  2. Scorpio in Theia, using the default strategy
  3. Scorpio in Theia, using the data-bridge strategy and injecting the data
  4. Scorpio in Theia, using the data-bridge strategy, not injecting any data (testing timeout logic)

Helper scripts

A bash script to build extensions locally and mount them into the theia image (change paths accordingly)

#!/bin/bash
set -e

SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
IMAGE="ghcr.io/ls1intum/theia/javascript:pr-47"
PORT="${PORT:-3000}"

echo "Building extensions..."
(cd "$SCRIPT_DIR/scorpio" && npm run build) &
pid1=$!
(cd "$SCRIPT_DIR/theia-data-bridge" && pnpm run build) &
pid2=$!

fail=0
wait $pid1 || fail=1
wait $pid2 || fail=1
if [ $fail -ne 0 ]; then
  echo "Build failed"
  exit 1
fi

# Create workspace directory if it doesn't exist
mkdir -p "$SCRIPT_DIR/workspace"

echo ""
echo "Starting Theia IDE on http://localhost:$PORT"
echo "Mounting local extensions:"
echo "  - scorpio"
echo "  - theia-data-bridge"
echo ""
echo "Press Ctrl+C to stop"
echo ""

# Run with mounted extensions
# Mount as VSIX-unpacked format (extension/ subdirectory expected by Theia)
docker run --rm -it \
  -p "$PORT:3000" \
  -p "16281:16281" \
  -e SCORPIO_THEIA_ENV_STRATEGY="data-bridge" \
  -v "$SCRIPT_DIR/scorpio:/home/theia/plugins/scorpio/extension:ro" \
  -v "$SCRIPT_DIR/theia-data-bridge:/home/theia/plugins/data-bridge/extension:ro" \
  -v "$SCRIPT_DIR/workspace:/home/project" \
  --name theia-dev \
  "$IMAGE"

Helper script to inject credentials using data-bridge

async function inject() {
    const response = await fetch("http://localhost:16281/data", {
        method: "POST",
        body: JSON.stringify({
            environment: {
                THEIA: "true",
                ARTEMIS_TOKEN: "TEST",
                ARTEMIS_URL: "TEST",
                GIT_URI: "TEST",
                GIT_USER: "TEST",
                GIT_MAIL: "TEST",
            },
        }),
        headers: {
            "Content-Type": "application/json",
        },
    });

    const text = await response.text();
    console.log(text);
}

inject().catch(console.error);

Review Progress

Screenshots

@lukaskratzel lukaskratzel changed the title Implement credential strategy pattern, using credential bridge Implement theia env strategy pattern, using data bridge Dec 7, 2025
@Mtze Mtze requested a review from a team December 8, 2025 15:36
Copy link

@KevinGruber2001 KevinGruber2001 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise looks very good 🚀


/**
* Strategy that polls the data bridge extension for environment variables.
* Used when SCORPIO_ENV_STRATEGY=data-bridge.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the Envrironment Variable is SCORPIO_THEIA_ENV_STRATEGY

if (error) {
reject(error);
} else {
resolve(stdout.trim());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Im not very sure about this.

I think resolve returns a empty string for unset ENV variables. Which results in THEIA_FLAG always beeing set to true (since it is empty string and not undefined)

Is this behaviour expected?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, will fix.

@lukaskratzel lukaskratzel requested a review from Mtze December 18, 2025 11:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Review

Development

Successfully merging this pull request may close these issues.

3 participants