Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions index.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ Use cases <docs/use_cases>
Slurm root cause analysis <docs/slurm_rca>
Loki query reference <docs/loki>
Headless integration <docs/skills/ai-factory-operations-agent-headless/SKILL>
Delegated Teams conversation bridge <utils/teams_graph_channel/README>
Teams bridge validation <utils/teams_graph_channel/VALIDATION>
```

```{toctree}
Expand Down
15 changes: 15 additions & 0 deletions utils/teams-graph-channel.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

// Keep the optional bridge's behavioral checks in the repository's existing CI test glob.
import './teams_graph_channel/channel.test.mjs';
import './teams_graph_channel/format.test.mjs';
import './teams_graph_channel/reformat.test.mjs';
import test from 'node:test';
import {execFileSync} from 'node:child_process';
import {fileURLToPath} from 'node:url';

test('Teams chat deployment generator preserves DM and group isolation', () => {
execFileSync('python3', [fileURLToPath(new URL('./teams_graph_channel/test_prepare.py', import.meta.url))],
{encoding:'utf8'});
});
50 changes: 46 additions & 4 deletions utils/teams-graph-probe.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ const source = readFileSync(new URL('./teams_graph_probe/probe.cjs', import.meta
async function run(scenario = 'send', config = {}) {
const requests = [], output = [];
const env = { MOSAIC_TEST_RUN_ID: 'test-fixture', MOSAIC_TEAMS_RECIPIENT_ID: recipientId };
if (scenario !== 'default') env.MOSAIC_TEST_PROBE_MODE = scenario === 'identity' ? 'identity' : 'send';
if (scenario !== 'default') env.MOSAIC_TEST_PROBE_MODE = ['identity','bind'].includes(scenario) ? scenario : 'send';
Object.assign(env, config);
const processMock = { env, stdout: { write: value => output.push(value) }, exitCode: 0 };
const context = vm.createContext({ URLSearchParams, AbortSignal, Date, JSON, encodeURIComponent,
const context = vm.createContext({ URL, URLSearchParams, AbortSignal, Date, JSON, encodeURIComponent,
process: processMock,
require: name => name === 'node:fs/promises' ? {
readFile: async () => scenario === 'invalid-json' ? '{secret:' + password : JSON.stringify(credentials),
Expand All @@ -36,7 +36,9 @@ async function run(scenario = 'send', config = {}) {
assert.equal(options.body.get('grant_type'), 'password');
if (scenario === 'identity' || scenario === 'default')
assert.equal(options.body.get('scope'), 'https://graph.microsoft.com/User.Read');
else assert.equal(options.body.get('scope'), 'https://graph.microsoft.com/User.Read https://graph.microsoft.com/Chat.Create https://graph.microsoft.com/ChatMessage.Send');
else if (env.MOSAIC_TEST_PROBE_MODE === 'bind-group')
assert.equal(options.body.get('scope'), 'https://graph.microsoft.com/User.Read https://graph.microsoft.com/Chat.ReadWrite');
else assert.equal(options.body.get('scope'), 'https://graph.microsoft.com/User.Read https://graph.microsoft.com/Chat.Create https://graph.microsoft.com/ChatMessage.Send' + (scenario === 'bind' ? ' https://graph.microsoft.com/Chat.ReadWrite' : ''));
if (scenario === 'mfa' || scenario === 'consent') return new Response(JSON.stringify({
error: 'invalid_grant', error_codes: [scenario === 'mfa' ? 50076 : 65001],
error_description: 'sensitive echo ' + password,
Expand All @@ -46,6 +48,17 @@ async function run(scenario = 'send', config = {}) {
assert.equal(options.headers.Authorization, 'Bearer ' + token);
if (url.includes('/me?')) return new Response(JSON.stringify({ id: senderId,
userPrincipalName: scenario === 'wrong-sender' ? 'other@example.invalid' : credentials.username }));
if (env.MOSAIC_TEST_PROBE_MODE === 'bind-group') {
assert.equal(options.method, 'GET');
if (url.endsWith('/members')) return new Response(JSON.stringify({value:[{userId:senderId}],
'@odata.nextLink': scenario === 'group-foreign-nextlink' ? 'https://example.invalid/v1.0/members'
: 'https://graph.microsoft.com/v1.0/chats/group-fixture/members?page=2'}));
if (url.endsWith('members?page=2')) return new Response(JSON.stringify({value:
scenario === 'group-nonmember' ? [] : [{userId:recipientId}]}));
if (url.endsWith('/chats/group-fixture')) return new Response(JSON.stringify({id:'group-fixture',
chatType:scenario === 'group-wrong-type' ? 'oneOnOne' : 'group'}));
throw new Error('Unexpected group URL');
}
if (url.endsWith('/chats')) {
const members = JSON.parse(options.body).members;
assert.deepEqual(members.map(m => m['user@odata.bind']), [
Expand All @@ -56,7 +69,7 @@ async function run(scenario = 'send', config = {}) {
if (scenario === 'graph-error') return new Response(JSON.stringify({ error: {
code: 'Forbidden', message: JSON.stringify({ password, token }),
}}), { status: 403 });
return new Response(JSON.stringify({ id: 'fixture-chat' }), { status: 201 });
return new Response(JSON.stringify({ id: 'fixture-chat', chatType: 'oneOnOne' }), { status: 201 });
}
if (url.endsWith('/messages')) {
assert.match(JSON.parse(options.body).body.content, /Run ID: test-fixture/);
Expand Down Expand Up @@ -86,6 +99,35 @@ test('Teams send uses explicit GUID members, preserves password characters and n
assert.equal(result.event.messageId, 'fixture-message');
});

test('Teams bind reuses the probe to establish a fixed chat without sending a message', async () => {
const result = await run('bind');
assert.equal(result.event.stage, 'bound');
assert.equal(result.event.chatId, 'fixture-chat');
assert.equal(result.requests.length, 3);
assert.ok(result.requests.every(r => !r.url.endsWith('/messages')));
});

const groupEnv={MOSAIC_TEST_PROBE_MODE:'bind-group',MOSAIC_TEAMS_GROUP_CHAT_ID:'group-fixture',
MOSAIC_TEAMS_ALLOWED_USER_IDS:recipientId};
test('Teams group binding only reads the exact group and all member pages', async () => {
const result=await run('group',groupEnv);
assert.equal(result.event.stage,'bound');assert.equal(result.event.chatType,'group');
assert.deepEqual(result.event.allowedUserIds,[recipientId]);assert.equal(result.requests.length,5);
assert.ok(result.requests.slice(1).every(r=>r.method==='GET' && !r.url.includes('/messages')));
});
for(const scenario of ['group-nonmember','group-wrong-type','group-foreign-nextlink'])
test(`Teams ${scenario} fails closed without changing or sending to the group`, async () => {
const result=await run(scenario,groupEnv);assert.equal(result.event.stage,'failed');
assert.ok(result.requests.every(r=>!r.url.includes('example.invalid') && !r.url.includes('/messages')));
});
test('Teams group binding rejects invalid explicit allowlists before login', async () => {
for(const delta of [{MOSAIC_TEAMS_ALLOWED_USER_IDS:''},{MOSAIC_TEAMS_ALLOWED_USER_IDS:'*'},
{MOSAIC_TEAMS_ALLOWED_USER_IDS:recipientId+','+recipientId},{MOSAIC_TEAMS_GROUP_CHAT_ID:''}]) {
const result=await run('group',{...groupEnv,...delta});assert.equal(result.requests.length,0);
assert.equal(result.event.reason,'invalid_group_binding');
}
});

for (const scenario of ['mfa', 'consent']) test(`Teams ${scenario} failure is retained without another password attempt`, async () => {
const result = await run(scenario);
assert.equal(result.requests.length, 1);
Expand Down
Loading
Loading