Test SSP Artifacts Locally

The following procedure shows how to test Self-Service Pipeline (SSP) artifacts locally, before deploying them to the Tetra Data Platform (TDP). Testing SSP artifacts locally can help reduce development time and catch issues before the artifacts are deployed to production.

For more information about how to set up SSPs, see the Hello, World! SSP Example and Example Use Cases for SSPs.

Best Practices for Testing SSP Artifacts Locally

  • Test early and often: Test task script functions locally before deployment
  • Use realistic test data: Create test files that match your expected inputs
  • Test error conditions: Include tests for edge cases and error handling
  • Version control: Keep your test scripts in version control
  • Automate testing: Consider integrating tests into CI/CD pipelines
  • Use real data when possible: Test with actual TDP files to catch integration issues early

Prerequisites

Before you can test SSP artifacts locally, make sure that you have the following:

Step 1: Set Up ts-cli Authentication for Testing Data in the TDP

To test your artifacts with real data from the TDP, first set up the required TetraScience CLI (ts-cli) authentication by doing the following:

  1. Download the configuration file that you created when configuring your TDP dependencies and authentication in the SSP Setup and Prerequisites. If you download this file from the TDP using the Download ts-sdk config button, the file is named ts-sdk-cfg.json. If you create your own configuration file, you can use any file name you want. In the Hello, World! SSP Example, the example configuration file name is auth.json.
  2. Save the configuration to your TetraScience CLI user profile by running the following command:
📘

NOTE

Make sure that you replace ts-sdk-cfg.json with the actual name of the configuration file you're using.

ts-cli save ~/Downloads/ts-sdk-cfg.json
  1. Delete the local configuration file. The required authentication information is now saved to your ts-cli user profile.

Step 2: Verify Your Project Folder Structure

If you haven't already, make sure that you've created the following basic SSP folder structure on your local machine in the directory where you want to keep your artifact code:

my-ssp-project/
├── task-script/
│   ├── config.json
│   ├── main.py
│   ├── requirements.txt
│   └── manifest.json (optional for testing)
├── protocol/
│   └── protocol.yml
└── tests/
    └── test_local.py

For an example SSP setup, see the Hello, World! SSP Example.

Step 3: Create a Local Testing Script

Create a file (for example, tests/test_local.py) in your local directory to test your task script by using the following example Python script:

from ts_sdk.testing.models import *
from pathlib import Path
import json

def invoke_task_script(file: File):
    """Invokes the print-hello-world task with the provided file as a trigger"""

    # Create test input data
    test_input = {"test_key": "test_value"}

    # Load task script from the parent directory
    task_script = TaskScript.from_manifest('../task-script/manifest.json')

    # Alternative: Create task script manually if no manifest
    # task_script = TaskScript(
    #     namespace="private-test",
    #     slug="test-taskscript",
    #     version="v1.0.0",
    #     path=Path('../task-script')
    # )

    # Set up testing context
    with Trigger(file=file), task_script:
        # Create task targeting the specific function
        task = Task(function='print-hello-world')

        # Run the task with test input
        result, error = task.run(test_input)

        # Verify results
        assert error is None
        print("Task execution results:")
        print(json.dumps(result, indent=2))

        return result

def test_hello_world_function():
    """Test the hello world function with inline file content."""

    # Create a workflow trigger with sample file content
    trigger_file = InlineFile(
        labels=[Label(name='test-label', value='test-value')],
        contents='Sample file content for testing'
    )

    invoke_task_script(trigger_file)

def test_with_local_file():
    """Test with a local file instead of inline content."""

    # Create a local test file
    test_file_path = Path('./test_data.txt')
    test_file_path.write_text('Local test file content')

    try:
        # Create workflow trigger with local file
        trigger_file = LocalFile(
            path=test_file_path,
            labels=[Label(name='test-label', value='test-value')]
        )

        invoke_task_script(trigger_file)

    finally:
        # Clean up test file
        if test_file_path.exists():
            test_file_path.unlink()

def test_with_remote_file():
    """Test with a remote file from TDP (requires authentication)."""

    # Set up authentication
    with UserConfigAuth():  # Uses saved ts-cli auth
    # Alternative: with ConfigFileAuth(path='path/to/ts-sdk-cfg.json'):

        # Create workflow trigger with remote file
        trigger_file = RemoteFile(
            id='your-file-id-here'  # Replace with actual file ID
        )

        invoke_task_script(trigger_file)

if __name__ == "__main__":
    print("Running local SSP artifact tests...")

    # Run basic test
    test_hello_world_function()

    # Run local file test
    test_with_local_file()

    # Uncomment to test with remote files (requires auth and valid file ID)
    # test_with_remote_file()

    print("All tests completed!")

Step 4: Run the Test

Execute your test script by running the following command:

cd tests
python test_local.py

Next Steps

To use your new artifacts on the TDP, deploy them to the platform by using the ts-cli publish command. Then, create a new pipeline that uses the protocol that you deployed.

To deploy a task script, see Deploy the Task Script in the Hello, World! SSP Example.

To deploy a protocol, see Deploy the Protocol in the Hello, World! SSP Example.

Documentation Feedback

Do you have questions about our documentation or suggestions for how we can improve it? Start a discussion in TetraConnect Hub. For access, see Access the TetraConnect Hub.

📘

NOTE

Feedback isn't part of the official TetraScience product documentation. TetraScience doesn't warrant or make any guarantees about the feedback provided, including its accuracy, relevance, or reliability. All feedback is subject to the terms set forth in the TetraConnect Hub Community Guidelines.