Skip to content

Bundle Azure template as default for "tm7 new" and "tm7 import dot"#4

Open
gholliday wants to merge 1 commit into
mainfrom
feat/default-template
Open

Bundle Azure template as default for "tm7 new" and "tm7 import dot"#4
gholliday wants to merge 1 commit into
mainfrom
feat/default-template

Conversation

@gholliday

Copy link
Copy Markdown
Owner

Problem

DotToTm7Mapper stamps Azure-specific stencil TypeIds (SE.TB.TMCore.AzureTrustBoundary, SE.DS.TMCore.AzureStorage, SE.P.TMCore.AzureAD, SE.P.TMCore.AzureAppServiceWebApp, SE.DS.TMCore.AzureKeyVault, SE.DF.TMCore.Request/Response) onto diagram elements. The previous required --template accepted any .tm7. When users passed a non-Azure template (e.g. TMT's default SDL threatmodelsample.tm7), the output .tm7 referenced TypeIds that weren't defined in its embedded KnowledgeBase, and TMT would show "model has validation issues" on open and downgrade every Azure-typed shape to its generic base (GE.TB.B / GE.DS / GE.P / GE.DF).

Solution

Embed samples/template.tm7 (the Azure Threat Model Template KB) as a resource and use it by default when --template is omitted.

Changes

  • src/Tm7.Cli/Tm7.Cli.csproj — embed samples/template.tm7 as Tm7.Cli.Resources.DefaultTemplate.tm7.
  • src/Tm7.Cli/Tm7File.cs — new Tm7File.LoadDefaultTemplate() that reads the embedded resource via Assembly.GetManifestResourceStream.
  • src/Tm7.Cli/Commands/NewCommand.cs and ImportCommand.cs--template is now optional. When omitted, the bundled Azure KB is used and the success message surfaces the KB name ((from bundled default template: Azure Threat Model Template)).
  • src/Tm7.Cli/Commands/ImportCommand.cs — flow TypeIds promoted to internal const ForwardFlowTypeId / ReverseFlowTypeId / GenericFlowTypeId so tests can reference the same strings production uses.
  • README.md and ExamplesCommand.cs — show the no---template form.

Tests

25/25 pass (5 new):

Test Guards
LoadDefaultTemplate_Succeeds_AndExposesAzureKb Embedded resource deserializes; KB Manifest name is "Azure Threat Model Template"; StandardElements non-empty
EmbeddedDefaultTemplate_MatchesSampleOnDisk SHA-256 drift guard between samples/template.tm7 and the baked-in resource
DefaultTemplate_DefinesEveryTypeIdEmittedByDotMapper Mapper-KB invariant — every recognized predicate/alias in DotToTm7Mapper.MapEntityType / MapBoundaryType plus the ImportCommand flow constants must resolve to a stencil in the bundled KB
AotExe_NewWithoutTemplate_UsesBundledAzureKb Published NativeAOT tm7 new with no --template produces a file whose embedded KB is the Azure template
AotExe_ImportDotWithoutTemplate_EmbedsAzureKbAndResolvesAllTypeIds Published NativeAOT tm7 import dot with no --template; every TypeId actually written into Borders/Lines resolves against the embedded KB (proxy for "TMT won't downgrade")

Verification

  • dotnet build -c Debug — green.
  • dotnet test — 25/25 pass.
  • dotnet publish src/Tm7.Cli -c Release -r win-arm64 — succeeds.
  • AOT exe tm7 new and tm7 import dot smoke-tested with no --template.

The DotToTm7Mapper stamps Azure-specific stencil TypeIds
(SE.TB.TMCore.AzureTrustBoundary, SE.DS.TMCore.AzureStorage,
SE.P.TMCore.AzureAD, SE.P.TMCore.AzureAppServiceWebApp,
SE.DS.TMCore.AzureKeyVault, SE.DF.TMCore.Request/Response) onto diagram
elements. The previous required --template accepted any .tm7 - when users
passed a non-Azure template (e.g. TMT's default SDL threatmodelsample.tm7),
the output .tm7 referenced TypeIds that weren't defined in its embedded
KnowledgeBase, and TMT would show "model has validation issues" on open and
downgrade every Azure-typed shape to its generic base.

Changes:
- Embed samples/template.tm7 as Tm7.Cli.Resources.DefaultTemplate.tm7.
- New Tm7File.LoadDefaultTemplate() reads the embedded resource.
- Make --template optional on "tm7 new" and "tm7 import dot"; fall back
  to the bundled Azure KB when omitted, and surface the KB name in the
  success message.
- Promote flow TypeId literals in ImportCommand to internal const so
  tests reference the same strings production uses.
- Update README and "tm7 examples" to show the no---template form.

Tests (25/25 pass, 5 new):
- LoadDefaultTemplate_Succeeds_AndExposesAzureKb
- EmbeddedDefaultTemplate_MatchesSampleOnDisk (SHA-256 drift guard)
- DefaultTemplate_DefinesEveryTypeIdEmittedByDotMapper (mapper-KB invariant
  covering every recognized predicate/alias + flow TypeIds via the constants)
- AotExe_NewWithoutTemplate_UsesBundledAzureKb
- AotExe_ImportDotWithoutTemplate_EmbedsAzureKbAndResolvesAllTypeIds

Co-authored-by: Copilot <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant