extract-and-test

A refactoring and testing guide for methods in a Windows-to-SolidWorks adapter, especially methods that combine COM calls, error handling, and nested functions. It explains how to split them into smaller helpers.

In plain words
What is it for?
Use it when restructuring a method in pywin32_adapter.py, such as extracting COM operations, fallback logic, error handling, or pure data transformations into separate helpers.
Why use it?
It makes code that is difficult to test in isolation easier to check and maintain. It also helps cover different success and failure paths with tests.

Skill for Claude CodeCodex

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/andrewbartels1/solidworksmcp-python/extract-and-test
Any agent
npx skills add andrewbartels1/SolidworksMCP-python --skill extract-and-test
Clone the repo
git clone --depth 1 https://github.com/andrewbartels1/SolidworksMCP-python

Made for: Claude Code, Codex.

Per session 112 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,607 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00112 $0.01607
Opus 5 $0.00056 $0.00804
Sonnet 5 $0.00022 $0.00321
Haiku 4.5 $0.00011 $0.00161

Measured 3d ago against content hash c9ee5989cfcc, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

extract-and-test scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 3d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.github/skills/extract-and-test/SKILL.md · 177 lines

How it starts

The opening of the file, as written. The whole thing — 177 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Extract & Test — pywin32_adapter.py

Apply this skill whenever a method in src/solidworks_mcp/adapters/pywin32_adapter.py contains:

  • Deeply nested try/except blocks or inner closures that can't be tested in isolation
  • Mixed concerns (COM selection strategy + fallback + error handling all in one body)
  • A closure that calls self._attempt(...) with an inner _run/_operation lambda

Step 1 — Read and Analyse

Read the target line range. For each logical block, fill in this table:

Concern COM calls involved Failure mode Return contract
(fill in) (fill in) (fill in) (fill in)

Apply these heuristics to determine the right helper shape:

Shape When to use
-> None (log, never raise) Setup/orientation side-effects — failure is acceptable
-> bool COM operation that writes a file; True = file exists
-> dict | None COM selection/query strategy; None = this strategy failed, try next
-> dict (raises on failure) Last-chance fallback or invoker — surface error to caller
@staticmethod Pure string/data transformation with no self state

Step 2 — Extract Helpers

Write one helper per concern. Insert helpers immediately before the async def they support.

def _<verb>_<noun>(self, <args>) -> <return type>:
    """<One-line description>.

    Args:
        <arg>: <description>

    Returns:
        <type>: <description>

    Raises:
        <ExceptionType>: <when>
    """
    ...

Examples by return contract:

# Graceful-failure helper — log, never raise
def _set_view_orientation(self, target_doc, orientation, view_const) -> None:
    try:
        target_doc.ShowNamedView2("", view_const)
    except Exception:
        logger.warning("Could not set view orientation to %s", orientation)

# Boolean helper — True = file written
def _save_screenshot_with_modelview(self, model_view, path, width, height) -> bool:
    try:
        model_view.SaveBitmapWithVariableSize(path, width, height)
        return os.path.exists(path)
    except Exception:
        return False

# Optional-dict helper — None = strategy failed, try next
def _try_select_by_extension(self, target_doc, candidates, feature_name) -> dict | None:
    for candidate in candidates:
        for entity_type in ENTITY_TYPES:
            try:
                if target_doc.Extension.SelectByID2(candidate, entity_type, 0, 0, 0, False, 0, None, 0):
                    return {"selected": True, "feature_name": feature_name, ...}
            except Exception:
                continue
    return None

# Raising helper — last-chance invoker
def _invoke_run_macro2(self, macro_path, module_name, proc_name) -> dict:
    result = self.swApp.RunMacro2(macro_path, module_name, proc_name, 0, 0)
    success = result[0] if isinstance(result, (list, tuple)) else bool(result)
    if not success:
        raise SolidWorksMCPError(f"RunMacro2 failed for {macro_path}")
    return {"macro_path": macro_path, "module_name": module_name}

Read the full file on GitHub · 177 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 3d ago First seen · 177 lines · 112 tokens per session scan A c9ee5989cfcc

Subscribe to this mod's changes

extract-and-test is a skill published in the GitHub repository andrewbartels1/SolidworksMCP-python (65 stars, last pushed 7d ago), licensed MIT. It adds 112 tokens to every session and 1,607 once invoked, about $0.0006 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.