Skip to content

forcedotcom/sf-skills / plugins/builder/agentforce-adlc/skills/agentforce-architecture-analyze

agentforce-architecture-analyze

Verified

Declared architecture snapshot for one Agentforce agent: planner, topics, actions, flows, Apex, prompt templates, and NGA plugins. Renders a human-readable architecture document and Mermaid invocation graph from design-time metadata (not runtime audit rows). TRIGGER when user asks to describe, diagram, inventory, audit, document, or diff (e.g. v3 vs v5) the architecture / action tree / topic structure / tool inventory of a specific agent by agent API name in a specific org. DO NOT TRIGGER for runtime session traces, conversation transcripts, generation timings, or gateway audit chains — this skill reads design-time metadata only (use agentforce-d360-analyze for session traces).

FileKindSize
README.mdmarkdown8.5 KB
SKILL.mdskill md17.5 KB
assets/cli/describe_sobject.yamlconfig317 B
assets/cli/describe_tooling_sobject.yamlconfig347 B
assets/cli/list_metadata_genaiprompttemplate.yamlconfig342 B
assets/cli/org_display.yamlconfig280 B
assets/cli/retrieve_genai_plugin.yamlconfig391 B
assets/cli/show_access_token.yamlconfig700 B
assets/mermaid/action_tree.mmdother986 B
assets/mermaid/data_flow.mmdother893 B
assets/mermaid/dependency_graph.mmdother810 B
assets/mermaid/invocation_sequence.mmdother1004 B
assets/mermaid/planner_state.mmdother813 B
assets/soql/apex_class_bodies_by_ids.soqlother103 B
assets/soql/apex_class_bodies_by_names.soqlother102 B
assets/soql/bot_definition_details.soqlother152 B
assets/soql/bot_version_lookup.soqlother186 B
assets/soql/flow_definition_by_ids.soqlother115 B
assets/soql/flow_definition_ids_by_names.soqlother146 B
assets/soql/flow_definition_view_by_durable_ids.soqlother180 B
assets/soql/flow_metadata_by_id.soqlother73 B
assets/soql/functions_by_plugins.soqlother317 B
assets/soql/planner_attrs_by_parent_ids.soqlother156 B
assets/soql/planner_bundle_functions.soqlother93 B
assets/soql/planner_definition_by_agent_chain.soqlother174 B
assets/soql/plugin_functions_by_plugin_ids.soqlother93 B
assets/soql/plugin_instructions_by_plugin_ids.soqlother168 B
assets/soql/plugins_by_planner.soqlother199 B
references/architecture_sections.mdmarkdown8.3 KB
references/contract.jsonconfig11.7 KB
references/soql_fields.mdmarkdown24.6 KB
scripts/_shared/__init__.pyscript82 B
scripts/_shared/fs_guard.pyexecutablescript12.8 KB
scripts/_shared/paths.pyscript3.9 KB
scripts/_shared/runtime.pyscript2.0 KB
scripts/_shared/sql.pyscript355 B
scripts/cache_check.pyexecutablescript8.9 KB
scripts/config.pyscript5.9 KB
scripts/emit_env.pyexecutablescript5.1 KB
scripts/emit_result.pyexecutablescript10.7 KB
scripts/fetch_soql.pyscript26.1 KB
scripts/finalize.pyexecutablescript11.8 KB
scripts/main.pyscript113.9 KB
scripts/metadata_listing.pyscript9.5 KB
scripts/parallel_retrieve.pyscript3.3 KB
scripts/parse_bundle.pyexecutablescript7.9 KB
scripts/parse_wave.pyexecutablescript36.1 KB
scripts/probe_channels.pyscript11.1 KB
scripts/render_architecture.pyscript40.0 KB
scripts/resolve_bot.pyexecutablescript9.4 KB
scripts/resolve_invocation_target.pyscript4.8 KB
scripts/rest_client.pyscript33.7 KB
scripts/retrieve_planner.pyscript464 B
scripts/sanitize.pyexecutablescript1013 B
scripts/sf_cli.pyscript12.3 KB
scripts/soql_loader.pyscript11.1 KB
scripts/summarize_tree.pyexecutablescript4.6 KB
scripts/tests/__init__.pyscript0 B
scripts/tests/_bootstrap.pyscript843 B
scripts/tests/fixtures/__init__.pyscript0 B
scripts/tests/fixtures/genai_payloads.pyscript12.5 KB
scripts/tests/test_cache_check.pyscript12.6 KB
scripts/tests/test_cache_check_main.pyscript10.4 KB
scripts/tests/test_config.pyscript3.8 KB
scripts/tests/test_end_to_end_fixture.pyscript26.2 KB
scripts/tests/test_finalize.pyscript11.2 KB
scripts/tests/test_flow_children_inflation.pyscript25.6 KB
scripts/tests/test_fs_guard.pyscript4.3 KB
scripts/tests/test_iterative_wave_b.pyscript19.0 KB
scripts/tests/test_main_pipeline.pyscript145.1 KB
scripts/tests/test_parallel_retrieve.pyscript4.8 KB
scripts/tests/test_parse_bundle.pyscript15.6 KB
scripts/tests/test_parse_wave.pyscript26.9 KB
scripts/tests/test_parse_wave_classifiers.pyscript8.6 KB
scripts/tests/test_parse_wave_helpers.pyscript14.3 KB
scripts/tests/test_parse_wave_main.pyscript16.4 KB
scripts/tests/test_per_branch_visited.pyscript9.5 KB
scripts/tests/test_probe_channels.pyscript13.3 KB
scripts/tests/test_probe_cli_recipes.pyscript8.2 KB
scripts/tests/test_render_architecture.pyscript32.7 KB
scripts/tests/test_resolve_bot.pyscript7.5 KB
scripts/tests/test_resolve_creds.pyscript12.0 KB
scripts/tests/test_resolve_invocation_target.pyscript5.2 KB
scripts/tests/test_rest_client.pyscript49.8 KB
scripts/tests/test_runtime_override.pyscript3.9 KB
scripts/tests/test_sf_cli.pyscript17.3 KB
scripts/tests/test_signature_stamping.pyscript18.0 KB
scripts/tests/test_skill_md_pipeline_block.pyscript12.7 KB
scripts/tests/test_soql_loader.pyscript21.3 KB
scripts/tests/test_summarize_tree.pyscript8.9 KB
scripts/tests/test_write_emit_ctx.pyscript19.2 KB
scripts/write_emit_ctx.pyexecutablescript14.1 KB

scripts/tests/test_soql_loader.py

View on GitHub
"""Tests for load_soql revalidates every substituted string."""
from __future__ import annotations

import tempfile
import unittest
from pathlib import Path
from unittest import mock

from . import _bootstrap  # noqa: F401 — sys.path setup


class LoadSoqlValidationTests(unittest.TestCase):
    """every param must be revalidated at the substitution boundary."""

    def setUp(self) -> None:
        # Use a throwaway SOQL_DIR populated per test so we don't depend on
        # the shipped assets having a specific template name.
        self._tmpdir = tempfile.TemporaryDirectory()
        self.soql_dir = Path(self._tmpdir.name)
        # Patch config.SOQL_DIR BEFORE importing soql_loader so the module
        # constant reflects the tmpdir. Because soql_loader binds SOQL_DIR
        # at import, we re-import it fresh under the patch.
        self._patch = mock.patch("config.SOQL_DIR", self.soql_dir)
        self._patch.start()
        # Force a fresh import so load_soql reads the patched SOQL_DIR.
        import importlib
        import soql_loader  # type: ignore
        importlib.reload(soql_loader)
        self.soql_loader = soql_loader

    def tearDown(self) -> None:
        self._patch.stop()
        self._tmpdir.cleanup()

    def _write_template(self, name: str, body: str) -> None:
        (self.soql_dir / f"{name}.soql").write_text(body)

    # ---- happy path -------------------------------------------------------

    def test_valid_param_substitutes(self):
        self._write_template(
            "bot_lookup",
            "SELECT Id FROM BotDefinition WHERE DeveloperName = '{{NAME}}'",
        )
        out = self.soql_loader.load_soql("bot_lookup", NAME="MyAgent")
        self.assertEqual(
            out,
            "SELECT Id FROM BotDefinition WHERE DeveloperName = 'MyAgent'",
        )

    def test_multiple_valid_params(self):
        self._write_template(
            "lookup",
            "SELECT Id FROM Obj WHERE A='{{A}}' AND B='{{B}}'",
        )
        out = self.soql_loader.load_soql("lookup", A="Foo", B="Bar_v2")
        self.assertIn("A='Foo'", out)
        self.assertIn("B='Bar_v2'", out)

    # ---- injection attempts must raise ------------------------------------

    def test_injection_quote_or_clause_raises(self):
        self._write_template("q", "SELECT Id FROM X WHERE Name='{{NAME}}'")
        with self.assertRaises(self.soql_loader.SoqlParamError) as ctx:
            self.soql_loader.load_soql("q", NAME="x' OR Id!=null--")
        self.assertEqual(ctx.exception.key, "NAME")

    def test_injection_drop_table_raises(self):
        self._write_template("q", "SELECT Id FROM X WHERE Name='{{NAME}}'")
        with self.assertRaises(self.soql_loader.SoqlParamError):
            self.soql_loader.load_soql("q", NAME="'; DROP TABLE x;--")

    def test_injection_or_1eq1_raises(self):
        self._write_template("q", "SELECT Id FROM X WHERE Name='{{NAME}}'")
        with self.assertRaises(self.soql_loader.SoqlParamError):
            self.soql_loader.load_soql("q", NAME="x OR 1=1")

    def test_whitespace_rejected(self):
        self._write_template("q", "SELECT Id FROM X WHERE Name='{{NAME}}'")
        with self.assertRaises(self.soql_loader.SoqlParamError):
            self.soql_loader.load_soql("q", NAME="x OR y")  # space

    def test_dash_rejected(self):
        # Common SOQL-injection payload prefix.
        self._write_template("q", "SELECT Id FROM X WHERE Name='{{NAME}}'")
        with self.assertRaises(self.soql_loader.SoqlParamError):
            self.soql_loader.load_soql("q", NAME="x-y")

    # ---- type errors ------------------------------------------------------

    def test_non_string_value_raises(self):
        self._write_template("q", "SELECT {{N}}")
        with self.assertRaises(self.soql_loader.SoqlParamError):
            self.soql_loader.load_soql("q", N=42)

    def test_none_value_raises(self):
        self._write_template("q", "SELECT {{N}}")
        with self.assertRaises(self.soql_loader.SoqlParamError):
            self.soql_loader.load_soql("q", N=None)

    def test_empty_string_raises(self):
        self._write_template("q", "SELECT {{N}}")
        with self.assertRaises(self.soql_loader.SoqlParamError):
            self.soql_loader.load_soql("q", N="")

    # ---- single-pass substitution guarantee -------------------------------

    def test_value_containing_other_placeholder_does_not_retrigger(self):
        """A valid value that contains `{{OTHER}}` must NOT trigger a
        second substitution pass on OTHER. str.replace is single-pass
        by contract; we assert that the validator's regex prevents any
        value from containing `{`, `}`, or whitespace in the first place
        — so the injection path is closed at validation, not at
        substitution.
        """
        self._write_template("q", "SELECT {{A}} AND {{B}}")
        # Reject values that carry placeholder syntax — the regex forbids
        # `{` and `}` (they're not in [A-Za-z0-9_]).
        with self.assertRaises(self.soql_loader.SoqlParamError):
            self.soql_loader.load_soql("q", A="{{B}}", B="safe")

    def test_raw_replace_is_single_pass(self):
        """Belt-and-braces: even if a value slipped through (it cannot,
        per the regex), Python's str.replace does not recursively scan
        the output. Simulate by bypassing the validator and confirming
        str.replace behavior directly.
        """
        template = "SELECT {{A}} AND {{B}}"
        # Substitute A first with a value that "looks like" the B
        # placeholder. str.replace for B should then replace the
        # template's own `{{B}}` — but A's embedded `{{B}}` should stay
        # (Python replaces left-to-right in a single pass; the output
        # of the A replacement is the NEW string and B's pass runs on
        # that new string). The assertion below therefore confirms
        # that B's replacement hits BOTH occurrences (the original and
        # the one inside A's substituted value) — demonstrating that
        # str.replace is NOT recursive on the ORIGINAL template alone,
        # but IS a single linear scan of the full post-A string.
        step1 = template.replace("{{A}}", "{{B}}")
        step2 = step1.replace("{{B}}", "replaced")
        # Both occurrences of `{{B}}` in step1 are replaced in a single
        # left-to-right pass. This is the property tested for.
        self.assertEqual(step2, "SELECT replaced AND replaced")
        # The safety net: if a caller EVER skipped revalidation and
        # allowed a `{{X}}` to reach substitution, the above behavior
        # could matter — which is PRECISELY why revalidates at
        # the boundary. The regex denies `{`, `}`, whitespace, making
        # this scenario unreachable in production.


class LoadSoqlNameValidationTests(unittest.TestCase):
    """the `name` argument is validated before any filesystem access.

    Without this, a caller that sources `name` from data (config file, user
    argument, discovered string) could read arbitrary files via traversal
    (`../../../etc/passwd`). The regex gate closes that before `read_text()`.
    """

    def setUp(self) -> None:
        self._tmpdir = tempfile.TemporaryDirectory()
        self.soql_dir = Path(self._tmpdir.name)
        self._patch = mock.patch("config.SOQL_DIR", self.soql_dir)
        self._patch.start()
        import importlib
        import soql_loader  # type: ignore
        importlib.reload(soql_loader)
        self.soql_loader = soql_loader

    def tearDown(self) -> None:
        self._patch.stop()
        self._tmpdir.cleanup()

    # ---- traversal attempts must raise before any file read ---------------

    def test_parent_traversal_raises(self):
        """`../../../etc/passwd` must be caught by validation, not by the
        filesystem. The error must be SoqlParamError (clearly labeled) —
        NOT a bare FileNotFoundError or a ValidationError with raw path.
        """
        with self.assertRaises(self.soql_loader.SoqlParamError) as ctx:
            self.soql_loader.load_soql("../../../etc/passwd")
        self.assertEqual(ctx.exception.key, "soql_template_name")
        # The absolute SOQL_DIR must NOT appear in the surfaced message.
        self.assertNotIn(str(self.soql_dir), str(ctx.exception))

    def test_dotdot_alone_raises(self):
        with self.assertRaises(self.soql_loader.SoqlParamError):
            self.soql_loader.load_soql("..")

    def test_slash_in_name_raises(self):
        """`/` is not in [A-Za-z0-9_], so `plugins/by_planner` must be
        caught at validation — never reach the filesystem."""
        with self.assertRaises(self.soql_loader.SoqlParamError):
            self.soql_loader.load_soql("plugins/by_planner")

    def test_backslash_in_name_raises(self):
        """Windows-style separators — belt and braces."""
        with self.assertRaises(self.soql_loader.SoqlParamError):
            self.soql_loader.load_soql("plugins\\by_planner")

    def test_absolute_path_raises(self):
        """A caller passing an absolute path (a different traversal variant)
        must still hit validation, not a false-negative file read."""
        with self.assertRaises(self.soql_loader.SoqlParamError):
            self.soql_loader.load_soql("/etc/passwd")

    def test_empty_name_raises(self):
        with self.assertRaises(self.soql_loader.SoqlParamError):
            self.soql_loader.load_soql("")

    def test_none_name_raises(self):
        with self.assertRaises(self.soql_loader.SoqlParamError):
            self.soql_loader.load_soql(None)  # type: ignore[arg-type]

    def test_whitespace_in_name_raises(self):
        with self.assertRaises(self.soql_loader.SoqlParamError):
            self.soql_loader.load_soql("bot lookup")

    def test_traversal_never_reads_filesystem(self):
        """Validation runs before any I/O — verify read_text is never
        called when the name is invalid. If the order ever flips, a bad
        name could still leak a FileNotFoundError with raw path info.
        """
        with mock.patch.object(Path, "read_text") as mock_read:
            with self.assertRaises(self.soql_loader.SoqlParamError):
                self.soql_loader.load_soql("../../../evil")
            mock_read.assert_not_called()


class LoadSoqlTemplateNotFoundTests(unittest.TestCase):
    """FileNotFoundError is translated into SoqlTemplateNotFound
    whose message is free of filesystem-path leakage.
    """

    def setUp(self) -> None:
        self._tmpdir = tempfile.TemporaryDirectory()
        self.soql_dir = Path(self._tmpdir.name)
        self._patch = mock.patch("config.SOQL_DIR", self.soql_dir)
        self._patch.start()
        import importlib
        import soql_loader  # type: ignore
        importlib.reload(soql_loader)
        self.soql_loader = soql_loader

    def tearDown(self) -> None:
        self._patch.stop()
        self._tmpdir.cleanup()

    def test_missing_template_raises_custom_exception(self):
        with self.assertRaises(self.soql_loader.SoqlTemplateNotFound) as ctx:
            self.soql_loader.load_soql("nonexistent_template")
        self.assertEqual(ctx.exception.name, "nonexistent_template")

    def test_missing_template_message_excludes_soql_dir(self):
        """The SOQL_DIR absolute path must NOT appear in the surfaced error
        string — information-disclosure hygiene. Attackers don't need to know
        where the skill install lives on disk.
        """
        with self.assertRaises(self.soql_loader.SoqlTemplateNotFound) as ctx:
            self.soql_loader.load_soql("nonexistent_template")
        msg = str(ctx.exception)
        self.assertNotIn(str(self.soql_dir), msg)
        self.assertNotIn(".soql", msg)
        # Template name IS allowed in the message — that's the triage signal.
        self.assertIn("nonexistent_template", msg)

    def test_missing_template_does_not_leak_via_cause_chain(self):
        """`raise ... from None` is load-bearing: without it, the
        FileNotFoundError (with its raw `filename` attribute) would be
        reachable via `exception.__cause__`. Verify the chain is severed.
        """
        try:
            self.soql_loader.load_soql("nonexistent_template")
        except self.soql_loader.SoqlTemplateNotFound as e:
            # `from None` sets __cause__ = None AND __suppress_context__ = True.
            # Either alone suppresses traceback rendering of the underlying
            # FileNotFoundError.
            self.assertIsNone(e.__cause__)
            self.assertTrue(e.__suppress_context__)
        else:
            self.fail("expected SoqlTemplateNotFound")

    def test_not_found_exception_is_distinct_from_file_not_found(self):
        """Callers should be able to tell 'template missing' apart from
        'permission denied / I/O error' at the except-clause layer.
        """
        self.assertFalse(
            issubclass(
                self.soql_loader.SoqlTemplateNotFound,
                FileNotFoundError,
            ),
            "SoqlTemplateNotFound must not subclass FileNotFoundError",
        )

    def test_valid_name_with_params_unchanged(self):
        """Regression: must not break the happy path."""
        (self.soql_dir / "lookup.soql").write_text(
            "SELECT Id FROM X WHERE Name = '{{NAME}}'"
        )
        out = self.soql_loader.load_soql("lookup", NAME="MyAgent")
        self.assertEqual(
            out,
            "SELECT Id FROM X WHERE Name = 'MyAgent'",
        )


class LoadSoqlInListParamTests(unittest.TestCase):
    """`load_soql_in` renders `WHERE X IN (...)` list placeholders.

    Same validation surface as `load_soql` — every list element passes
    through `fs_guard.validate_api_name`. Empty lists fail fast (SOQL
    `WHERE X IN ()` is invalid). Dedup + sort are load-bearing for
    stable cache keys.
    """

    def setUp(self) -> None:
        self._tmpdir = tempfile.TemporaryDirectory()
        self.soql_dir = Path(self._tmpdir.name)
        self._patch = mock.patch("config.SOQL_DIR", self.soql_dir)
        self._patch.start()
        import importlib
        import soql_loader  # type: ignore
        importlib.reload(soql_loader)
        self.soql_loader = soql_loader

    def tearDown(self) -> None:
        self._patch.stop()
        self._tmpdir.cleanup()

    def _write_template(self, name: str, body: str) -> None:
        (self.soql_dir / f"{name}.soql").write_text(body)

    # ---- happy path ------------------------------------------------------

    def test_list_params_render_single_quoted_comma_joined(self):
        self._write_template(
            "apex_by_names",
            "SELECT Id FROM ApexClass WHERE Name IN ({{NAMES_LIST}})",
        )
        out = self.soql_loader.load_soql_in(
            "apex_by_names",
            list_params={"NAMES_LIST": ["ClassA", "ClassB"]},
        )
        self.assertIn("WHERE Name IN ('ClassA','ClassB')", out)

    def test_mixed_string_and_list_params(self):
        self._write_template(
            "functions_q",
            "SELECT Id FROM GenAiFunctionDefinition "
            "WHERE PlannerId = '{{PLANNER_ID}}' OR PluginId IN ({{PLUGIN_IDS}})",
        )
        out = self.soql_loader.load_soql_in(
            "functions_q",
            string_params={"PLANNER_ID": "X"},
            list_params={"PLUGIN_IDS": ["P1", "P2"]},
        )
        self.assertIn("PlannerId = 'X'", out)
        self.assertIn("PluginId IN ('P1','P2')", out)

    def test_string_params_optional(self):
        """string_params defaults to None — list_params alone should work."""
        self._write_template(
            "flow_by_names",
            "SELECT Id FROM FlowDefinition WHERE DeveloperName IN ({{NAMES_LIST}})",
        )
        out = self.soql_loader.load_soql_in(
            "flow_by_names",
            list_params={"NAMES_LIST": ["Flow_A"]},
        )
        self.assertIn("IN ('Flow_A')", out)

    # ---- validation: list elements must match api_name regex ---------------

    def test_injection_in_list_element_raises_with_list_key(self):
        """A SOQL injection attempt inside a list element must raise
        SoqlParamError whose `key` is the LIST key (not the element
        index or a synthetic name) — so the caller can log / mark
        `_unresolved[NAMES_LIST]` at the upstream boundary.
        """
        self._write_template(
            "q", "SELECT Id FROM ApexClass WHERE Name IN ({{NAMES_LIST}})",
        )
        with self.assertRaises(self.soql_loader.SoqlParamError) as ctx:
            self.soql_loader.load_soql_in(
                "q",
                list_params={"NAMES_LIST": ["ClassA", "ClassB'; DROP TABLE x;--"]},
            )
        self.assertEqual(ctx.exception.key, "NAMES_LIST")

    def test_non_string_element_raises(self):
        self._write_template("q", "SELECT Id FROM X WHERE Id IN ({{IDS}})")
        with self.assertRaises(self.soql_loader.SoqlParamError) as ctx:
            self.soql_loader.load_soql_in(
                "q", list_params={"IDS": ["ClassA", 42]},
            )
        self.assertEqual(ctx.exception.key, "IDS")

    def test_whitespace_in_list_element_raises(self):
        self._write_template("q", "SELECT Id FROM X WHERE Id IN ({{IDS}})")
        with self.assertRaises(self.soql_loader.SoqlParamError):
            self.soql_loader.load_soql_in(
                "q", list_params={"IDS": ["ClassA", "x OR 1=1"]},
            )

    # ---- empty list fails fast --------------------------------------------

    def test_empty_list_raises(self):
        """SOQL `WHERE X IN ()` is a syntax error; fail at the loader,
        not at the CLI. The reason string must mention empty so the
        `_unresolved` bucket can be tagged distinctly from injection.
        """
        self._write_template("q", "SELECT Id FROM X WHERE Id IN ({{IDS}})")
        with self.assertRaises(self.soql_loader.SoqlParamError) as ctx:
            self.soql_loader.load_soql_in("q", list_params={"IDS": []})
        self.assertEqual(ctx.exception.key, "IDS")
        self.assertIn("empty", ctx.exception.reason.lower())

    def test_list_params_not_a_list_raises(self):
        """Defensive: a dict or string passed in `list_params[KEY]`
        must be rejected — silently iterating a string would produce
        one-char-per-element SOQL, which is worse than an explicit error.
        """
        self._write_template("q", "SELECT Id FROM X WHERE Id IN ({{IDS}})")
        with self.assertRaises(self.soql_loader.SoqlParamError):
            # type: ignore[arg-type]
            self.soql_loader.load_soql_in("q", list_params={"IDS": "notalist"})

    # ---- dedupe + deterministic order -------------------------------------

    def test_dedupe_eliminates_duplicates(self):
        self._write_template("q", "SELECT Id FROM X WHERE Name IN ({{NS}})")
        out = self.soql_loader.load_soql_in(
            "q", list_params={"NS": ["ClassA", "ClassA", "ClassB"]},
        )
        self.assertEqual(out.count("'ClassA'"), 1)
        self.assertEqual(out.count("'ClassB'"), 1)

    def test_output_is_sorted_for_deterministic_order(self):
        """Stable cache-key requirement: input order MUST NOT affect
        output. `sorted(set(...))` lands ClassA before ClassB regardless
        of input order.
        """
        self._write_template("q", "SELECT Id FROM X WHERE Name IN ({{NS}})")
        out1 = self.soql_loader.load_soql_in(
            "q", list_params={"NS": ["ClassB", "ClassA"]},
        )
        out2 = self.soql_loader.load_soql_in(
            "q", list_params={"NS": ["ClassA", "ClassB"]},
        )
        self.assertEqual(out1, out2)
        # And the order is alphabetical, not input-dependent.
        self.assertLess(out1.index("'ClassA'"), out1.index("'ClassB'"))

    # ---- scalar validation path shared with load_soql ---------------------

    def test_scalar_injection_still_raises(self):
        """string_params go through the same validator as `load_soql` —
        no shortcut. A SOQL-injection attempt in a scalar must still
        surface SoqlParamError.
        """
        self._write_template(
            "q",
            "SELECT Id FROM X WHERE P = '{{PID}}' OR Q IN ({{LIST}})",
        )
        with self.assertRaises(self.soql_loader.SoqlParamError) as ctx:
            self.soql_loader.load_soql_in(
                "q",
                string_params={"PID": "x' OR Id!=null--"},
                list_params={"LIST": ["A"]},
            )
        self.assertEqual(ctx.exception.key, "PID")

    # ---- template-name validation reused ----------------------------------

    def test_template_traversal_raises(self):
        with self.assertRaises(self.soql_loader.SoqlParamError) as ctx:
            self.soql_loader.load_soql_in(
                "../../../evil", list_params={"IDS": ["A"]},
            )
        self.assertEqual(ctx.exception.key, "soql_template_name")

    def test_missing_template_raises_template_not_found(self):
        with self.assertRaises(self.soql_loader.SoqlTemplateNotFound):
            self.soql_loader.load_soql_in(
                "nonexistent_for_in", list_params={"IDS": ["A"]},
            )

    # ---- existing load_soql unchanged -------------------------------------

    def test_load_soql_signature_untouched(self):
        """contract: `load_soql(name, **params)` keeps its original
        signature — no kwargs-only, no extra params. A caller that still
        uses the old form must keep working.
        """
        self._write_template("q", "SELECT Id FROM X WHERE Name = '{{NAME}}'")
        out = self.soql_loader.load_soql("q", NAME="Foo")
        self.assertIn("'Foo'", out)


if __name__ == "__main__":
    unittest.main()
rea-analysis-optimizationmorluto/reaOptimize REA providers and shared analysis workflows for agent context, latency, CPU, and memory while preserving correctness and Evidence. Use for analysis bottlenecks and cache or query design; CI/test-suite optimization belongs to rea-ci-tests-audit.Stars: 471kUpdated Claude CodeCodexVerifiedInstall
rea-ci-tests-auditmorluto/reaAudit REA CI and test suites for correctness, fixture drift, false passes, and measured performance; use for suite or workflow investigations and efficiency changes, rather than ordinary feature testing or a single test failure.Stars: 471kUpdated Claude CodeCodexVerifiedInstall
rea-tool-designmorluto/reaAudit, investigate, design, or change REA investigation tools, CLI/MCP contracts, provider capabilities, and Evidence semantics.Stars: 471kUpdated Claude CodeCodexVerifiedInstall
ponytail-auditDietrichGebert/ponytailQuality audit of the whole repo: bugs, security, real load, missing tests, speed, and what to delete. Most important first.Stars: 194kUpdated Claude CodeCodexVerifiedInstall