Skip to content

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

agentforce-d360-analyze

Verified

Data Cloud 360° view of a single Agentforce session. TRIGGER when user asks to trace, inspect, summarize, or describe a specific Agentforce session by session id (Agent Session UUID `019d…` or MessagingSession id `0Mw…`). Also triggers on session discovery — find/list/search sessions by time, agent, channel, outcome, or conversation text — when the user has no session id yet. DO NOT TRIGGER for design-time architecture questions (use agentforce-architecture-analyze instead) or for runtime perf/latency/SLO questions that require platform telemetry beyond Data Cloud.

FileKindSize
README.mdmarkdown6.2 KB
SKILL.mdskill md13.2 KB
assets/dc/app_generation.sqlother1.9 KB
assets/dc/content_category.sqlother1.5 KB
assets/dc/content_quality.sqlother1.3 KB
assets/dc/discover_sessions.sqlother2.3 KB
assets/dc/feedback.sqlother1.5 KB
assets/dc/feedback_details.sqlother1.3 KB
assets/dc/gateway_records.sqlother1.6 KB
assets/dc/gateway_request_llm.sqlother1.6 KB
assets/dc/gateway_request_metadata.sqlother1.5 KB
assets/dc/gateway_request_tags.sqlother1.4 KB
assets/dc/gateway_requests.sqlother3.4 KB
assets/dc/gateway_responses.sqlother1.7 KB
assets/dc/generations.sqlother1.9 KB
assets/dc/interactions.sqlother2.0 KB
assets/dc/messages.sqlother2.1 KB
assets/dc/messaging_session.sqlother1.7 KB
assets/dc/moment_interactions.sqlother1.4 KB
assets/dc/moments.sqlother1.5 KB
assets/dc/participants.sqlother1.8 KB
assets/dc/sessions.sqlother3.0 KB
assets/dc/steps.sqlother2.6 KB
assets/dc/tag_associations.sqlother1.7 KB
assets/dc/tag_definition_associations.sqlother1.4 KB
assets/dc/tag_definitions.sqlother1.8 KB
assets/dc/tags.sqlother1.3 KB
assets/dc/telemetry_spans.sqlother2.1 KB
references/artifacts.mdmarkdown2.7 KB
references/dc_dmo_fields.mdmarkdown42.1 KB
references/dc_pipeline_contract.mdmarkdown26.3 KB
scripts/_shared/__init__.pyscript122 B
scripts/_shared/cli_override.pyscript3.3 KB
scripts/_shared/fs_guard.pyexecutablescript13.2 KB
scripts/_shared/paths.pyscript5.8 KB
scripts/_shared/runtime.pyscript2.0 KB
scripts/_shared/sql.pyscript548 B
scripts/assemble_dc.pyscript69.6 KB
scripts/config.pyscript1.8 KB
scripts/dc.pyscript13.8 KB
scripts/discover_sessions.pyscript21.1 KB
scripts/fetch_dc.pyscript45.1 KB
scripts/render_dc.pyscript69.7 KB
scripts/resolve_session.pyscript10.8 KB
scripts/storage.pyscript3.1 KB
scripts/tests/__init__.pyscript0 B
scripts/tests/_bootstrap.pyscript483 B
scripts/tests/fixtures/__init__.pyscript0 B
scripts/tests/fixtures/synthetic_session.pyscript14.6 KB
scripts/tests/test_assemble_dc_bootstrap_and_mode.pyscript4.2 KB
scripts/tests/test_assemble_dc_gateway_direct.pyscript8.3 KB
scripts/tests/test_assemble_dc_gateway_direct_integration.pyscript6.4 KB
scripts/tests/test_assemble_dc_helpers.pyscript10.0 KB
scripts/tests/test_assemble_dc_integration.pyscript9.3 KB
scripts/tests/test_dc_and_resolve_session.pyscript26.7 KB
scripts/tests/test_default_target_org.pyscript18.8 KB
scripts/tests/test_discover_sessions.pyscript19.0 KB
scripts/tests/test_discover_sessions_grep_ci.pyscript8.2 KB
scripts/tests/test_fetch_dc_helpers.pyscript10.6 KB
scripts/tests/test_fetch_dc_identity.pyscript22.0 KB
scripts/tests/test_fetch_dc_main.pyscript9.4 KB
scripts/tests/test_fetch_dc_waterfall.pyscript8.6 KB
scripts/tests/test_fetch_dc_waterfall_full.pyscript11.2 KB
scripts/tests/test_identity_coherence.pyscript13.8 KB
scripts/tests/test_render_dc_branches.pyscript9.9 KB
scripts/tests/test_render_dc_gateway_direct.pyscript5.1 KB
scripts/tests/test_render_dc_helpers.pyscript10.5 KB
scripts/tests/test_render_dc_integration.pyscript7.7 KB
scripts/tests/test_render_dc_planner_llm_calls.pyscript11.8 KB
scripts/tests/test_render_dc_show_prompts_gating.pyscript8.7 KB
scripts/tests/test_resolve_from_disk.pyscript4.1 KB
scripts/tests/test_resolve_session_main.pyscript5.2 KB
scripts/tests/test_runtime_override.pyscript4.2 KB
scripts/tests/test_session_shape.pyscript3.5 KB
scripts/tests/test_session_shape_dropped_by_stdm.pyscript3.5 KB
scripts/tests/test_skill_md_prefix_block.pyscript6.8 KB

scripts/tests/test_assemble_dc_helpers.py

View on GitHub
"""Tests for ``assemble_dc`` pure helpers — independent of disk fixtures.

Complements ``test_assemble_dc_gateway_direct.py`` (binding chain) by
hitting the small, mechanical helpers that bridge raw DC rows and the
assembled tree:

- ``_clean``           NOT_SET sentinel collapse
- ``_harvest_str``     unescape + quote-strip + UNSET_VALUE
- ``_ts``              ISO-8601 → datetime; NOT_SET / non-string → None
- ``_index_unique``    PK dedup with first-write-wins + collision record
- ``_groupby``         group rows by FK, dropping NOT_SET keys
- ``_extract_trace_id`` primary col with HTML-escaped fallback
- ``_tier``            ACTION < TOPIC < GUARDRAIL < other
- ``_window_contains`` half-open / closed timestamp interval semantics
- ``_load``            disk read with malformed-json tolerance
"""
from __future__ import annotations

import json
import unittest
from datetime import datetime, timezone
from pathlib import Path
from tempfile import TemporaryDirectory

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

import assemble_dc  # type: ignore


# -----------------------------------------------------------------------------
# _clean — NOT_SET → None
# -----------------------------------------------------------------------------


class CleanTests(unittest.TestCase):

    def test_not_set_token_returns_none(self):
        self.assertIsNone(assemble_dc._clean("NOT_SET"))

    def test_empty_string_returns_none(self):
        self.assertIsNone(assemble_dc._clean(""))

    def test_actual_value_passes_through(self):
        self.assertEqual(assemble_dc._clean("real value"), "real value")
        self.assertEqual(assemble_dc._clean(42), 42)


# -----------------------------------------------------------------------------
# _harvest_str — unescape + quote-strip + UNSET_VALUE collapse
# -----------------------------------------------------------------------------


class HarvestStrTests(unittest.TestCase):

    def test_none_returns_none(self):
        self.assertIsNone(assemble_dc._harvest_str(None))

    def test_unescapes_html_entities(self):
        self.assertEqual(
            assemble_dc._harvest_str("&quot;0Xx000&quot;"),
            "0Xx000",
        )

    def test_strips_outer_double_quotes(self):
        self.assertEqual(assemble_dc._harvest_str('"value"'), "value")

    def test_unset_value_collapses_to_none(self):
        self.assertIsNone(assemble_dc._harvest_str("UNSET_VALUE"))

    def test_not_set_collapses_to_none(self):
        self.assertIsNone(assemble_dc._harvest_str("NOT_SET"))

    def test_empty_string_collapses_to_none(self):
        self.assertIsNone(assemble_dc._harvest_str(""))


# -----------------------------------------------------------------------------
# _ts — ISO-8601 timestamp parsing
# -----------------------------------------------------------------------------


class TsTests(unittest.TestCase):

    def test_parses_iso_z_timestamp(self):
        out = assemble_dc._ts("2026-04-22T10:00:00Z")
        self.assertEqual(out, datetime(2026, 4, 22, 10, 0, 0, tzinfo=timezone.utc))

    def test_parses_iso_offset_timestamp(self):
        out = assemble_dc._ts("2026-04-22T10:00:00+00:00")
        self.assertEqual(out, datetime(2026, 4, 22, 10, 0, 0, tzinfo=timezone.utc))

    def test_returns_none_for_non_string(self):
        self.assertIsNone(assemble_dc._ts(None))
        self.assertIsNone(assemble_dc._ts(12345))

    def test_returns_none_for_not_set(self):
        self.assertIsNone(assemble_dc._ts("NOT_SET"))
        self.assertIsNone(assemble_dc._ts(""))

    def test_returns_none_for_unparseable(self):
        self.assertIsNone(assemble_dc._ts("not-a-timestamp"))


# -----------------------------------------------------------------------------
# _index_unique
# -----------------------------------------------------------------------------


class IndexUniqueTests(unittest.TestCase):

    def test_builds_dict_keyed_by_field(self):
        rows = [{"id": "a", "v": 1}, {"id": "b", "v": 2}]
        out = assemble_dc._index_unique(rows, "id", [], dmo_label="t")
        self.assertEqual(set(out.keys()), {"a", "b"})

    def test_first_write_wins_on_collision(self):
        rows = [{"id": "a", "v": 1}, {"id": "a", "v": 2}]
        collisions: list[dict] = []
        out = assemble_dc._index_unique(rows, "id", collisions, dmo_label="dmo1")
        self.assertEqual(out["a"]["v"], 1)
        self.assertEqual(len(collisions), 1)
        self.assertEqual(collisions[0]["dmo"], "dmo1")
        self.assertEqual(collisions[0]["key"], "a")

    def test_skips_NOT_SET_keys(self):
        rows = [{"id": "NOT_SET", "v": 1}, {"id": "", "v": 2}, {"id": "a", "v": 3}]
        out = assemble_dc._index_unique(rows, "id", [], dmo_label="t")
        self.assertEqual(set(out.keys()), {"a"})


# -----------------------------------------------------------------------------
# _groupby
# -----------------------------------------------------------------------------


class GroupbyTests(unittest.TestCase):

    def test_groups_rows_by_key(self):
        rows = [{"k": "a", "v": 1}, {"k": "b", "v": 2}, {"k": "a", "v": 3}]
        out = assemble_dc._groupby(rows, "k")
        self.assertEqual([r["v"] for r in out["a"]], [1, 3])
        self.assertEqual([r["v"] for r in out["b"]], [2])

    def test_skips_NOT_SET_keys(self):
        rows = [{"k": "a", "v": 1}, {"k": "NOT_SET", "v": 2}]
        out = assemble_dc._groupby(rows, "k")
        self.assertNotIn("NOT_SET", out)
        self.assertIn("a", out)


# -----------------------------------------------------------------------------
# _extract_trace_id
# -----------------------------------------------------------------------------


class ExtractTraceIdTests(unittest.TestCase):

    def test_uses_primary_column_when_populated(self):
        out = assemble_dc._extract_trace_id({"ssot__TelemetryTraceId__c": "abc"})
        self.assertEqual(out, "abc")

    def test_falls_back_to_html_escaped_attribute_text(self):
        out = assemble_dc._extract_trace_id({
            "ssot__TelemetryTraceId__c": "",
            "ssot__AttributeText__c": '&quot;internalTraceId&quot;:&quot;deadbeef&quot;',
        })
        self.assertEqual(out, "deadbeef")

    def test_returns_none_when_no_trace_id_anywhere(self):
        out = assemble_dc._extract_trace_id({
            "ssot__TelemetryTraceId__c": "",
            "ssot__AttributeText__c": "no trace here",
        })
        self.assertIsNone(out)

    def test_returns_none_for_NOT_SET(self):
        out = assemble_dc._extract_trace_id({
            "ssot__TelemetryTraceId__c": "NOT_SET",
            "ssot__AttributeText__c": "",
        })
        self.assertIsNone(out)


# -----------------------------------------------------------------------------
# _tier — ACTION < TOPIC < GUARDRAIL < other
# -----------------------------------------------------------------------------


class TierTests(unittest.TestCase):

    def test_action_step_is_lowest_tier(self):
        self.assertLess(
            assemble_dc._tier("ACTION_STEP"),
            assemble_dc._tier("TOPIC_STEP"),
        )

    def test_topic_step_outranks_guardrails(self):
        self.assertLess(
            assemble_dc._tier("TOPIC_STEP"),
            assemble_dc._tier("TRUST_GUARDRAILS_STEP"),
        )

    def test_unknown_step_type_falls_to_end(self):
        self.assertEqual(
            assemble_dc._tier("MYSTERY"),
            len(assemble_dc._TIER_ORDER),
        )


# -----------------------------------------------------------------------------
# _window_contains
# -----------------------------------------------------------------------------


class WindowContainsTests(unittest.TestCase):

    def _ts(self, h, m, s):
        return datetime(2026, 4, 22, h, m, s, tzinfo=timezone.utc)

    def test_in_range_inclusive_of_start_and_end(self):
        gw = self._ts(10, 0, 5)
        self.assertTrue(
            assemble_dc._window_contains(gw, self._ts(10, 0, 0), self._ts(10, 0, 10))
        )

    def test_open_ended_when_end_is_none(self):
        gw = self._ts(11, 0, 0)
        self.assertTrue(
            assemble_dc._window_contains(gw, self._ts(10, 0, 0), None)
        )

    def test_returns_false_when_start_is_none(self):
        gw = self._ts(10, 0, 0)
        self.assertFalse(
            assemble_dc._window_contains(gw, None, self._ts(11, 0, 0))
        )

    def test_returns_false_when_before_start(self):
        gw = self._ts(9, 0, 0)
        self.assertFalse(
            assemble_dc._window_contains(gw, self._ts(10, 0, 0), self._ts(11, 0, 0))
        )

    def test_returns_false_when_after_end(self):
        gw = self._ts(12, 0, 0)
        self.assertFalse(
            assemble_dc._window_contains(gw, self._ts(10, 0, 0), self._ts(11, 0, 0))
        )


# -----------------------------------------------------------------------------
# _load — disk read with tolerance
# -----------------------------------------------------------------------------


class LoadTests(unittest.TestCase):

    def test_returns_empty_list_when_file_missing(self):
        with TemporaryDirectory() as t:
            warnings: list[str] = []
            self.assertEqual(
                assemble_dc._load(Path(t), "missing", warnings), []
            )
            # Missing file is normal — no warning recorded.
            self.assertEqual(warnings, [])

    def test_returns_loaded_rows_when_file_valid(self):
        with TemporaryDirectory() as t:
            tmp = Path(t)
            (tmp / "dc.sessions.json").write_text(json.dumps([{"a": 1}, {"a": 2}]))
            warnings: list[str] = []
            out = assemble_dc._load(tmp, "sessions", warnings)
            self.assertEqual(out, [{"a": 1}, {"a": 2}])
            self.assertEqual(warnings, [])

    def test_returns_empty_list_and_records_warning_on_malformed_json(self):
        with TemporaryDirectory() as t:
            tmp = Path(t)
            (tmp / "dc.broken.json").write_text("<<<not json>>>")
            warnings: list[str] = []
            out = assemble_dc._load(tmp, "broken", warnings)
            self.assertEqual(out, [])
            self.assertEqual(warnings, ["broken"])


if __name__ == "__main__":
    unittest.main()
brainstormingobra/superpowersYou MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation).Stars: 322kUpdated Claude CodeCodexVerifiedInstall
brand-guidelinesanthropics/skillsApplies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand colors or style guidelines, visual formatting, or company design standards apply.Stars: 198kUpdated Claude CodeCodexVerifiedInstall
frontend-designanthropics/skillsGuidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making choices that don't read as templated defaults.Stars: 198kUpdated Claude CodeCodexVerifiedInstall
mcp-builderanthropics/skillsGuide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK).Stars: 198kUpdated Claude CodeCodexVerifiedInstall