Skip to content

test(msteams): add comprehensive tests for graph-upload module#8964

Closed
RajdeepKushwaha5 wants to merge 5 commits intoopenclaw:mainfrom
RajdeepKushwaha5:main
Closed

test(msteams): add comprehensive tests for graph-upload module#8964
RajdeepKushwaha5 wants to merge 5 commits intoopenclaw:mainfrom
RajdeepKushwaha5:main

Conversation

@RajdeepKushwaha5
Copy link
Copy Markdown

@RajdeepKushwaha5 RajdeepKushwaha5 commented Feb 4, 2026

Summary

Adds unit tests for the MS Teams graph-upload module which previously had no test coverage.

Changes

  • Add 23 new tests covering all exported functions in graph-upload.ts
  • Tests cover success cases, error handling, and edge cases
  • Uses mock fetch pattern consistent with other msteams tests

Testing

  • All tests pass locally (npx vitest run extensions/msteams/src/graph-upload.test.ts)
  • No TypeScript errors

Checklist

  • Tests focused on one module
  • Follows existing testing patterns
  • AI-assisted (Claude Opus 4.5 with Copilot)

Greptile Overview

Greptile Summary

This PR adds a new Vitest test suite for the MS Teams graph-upload module, covering OneDrive/SharePoint upload helpers, sharing-link creation, drive-item property lookups, and chat member retrieval via injected fetchFn and a mocked access token provider.

The approach mirrors the module’s dependency-injection pattern (passing fetchFn + token provider) and exercises both success and error paths for the exported functions in extensions/msteams/src/graph-upload.ts.

Confidence Score: 3/5

  • This PR is low-risk functionally, but several test assertions appear to be incorrect and may fail in CI.
  • Only a new test file is added, but multiple expectations don’t match the actual error strings thrown by the implementation (notably where response bodies are appended). I couldn’t execute tests in this environment (node/pnpm unavailable), so confidence relies on static verification against the source.
  • extensions/msteams/src/graph-upload.test.ts

(2/5) Greptile learns from your feedback when you react with thumbs up/down!

Copilot AI review requested due to automatic review settings February 4, 2026 17:24
@openclaw-barnacle openclaw-barnacle bot added the channel: msteams Channel integration: msteams label Feb 4, 2026
Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 file reviewed, 3 comments

Edit Code Review Agent Settings | Greptile

Comment on lines +336 to +344
await expect(
uploadToSharePoint({
buffer: Buffer.from("test"),
filename: "test.txt",
tokenProvider,
siteId: "site-123",
fetchFn: mockFetch,
}),
).rejects.toThrow("SharePoint upload failed: 500 Internal Server Error");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incorrect error expectation

uploadToSharePoint includes the response body in its error message (... - ${body}), but this test asserts the message without the trailing - SharePoint is unavailable. With the current implementation in extensions/msteams/src/graph-upload.ts:197-200, this assertion should fail.

Suggested change
await expect(
uploadToSharePoint({
buffer: Buffer.from("test"),
filename: "test.txt",
tokenProvider,
siteId: "site-123",
fetchFn: mockFetch,
}),
).rejects.toThrow("SharePoint upload failed: 500 Internal Server Error");
).rejects.toThrow("SharePoint upload failed: 500 Internal Server Error - SharePoint is unavailable");
Prompt To Fix With AI
This is a comment left during a code review.
Path: extensions/msteams/src/graph-upload.test.ts
Line: 336:344

Comment:
**Incorrect error expectation**

`uploadToSharePoint` includes the response body in its error message (`... - ${body}`), but this test asserts the message without the trailing ` - SharePoint is unavailable`. With the current implementation in `extensions/msteams/src/graph-upload.ts:197-200`, this assertion should fail.

```suggestion
      ).rejects.toThrow("SharePoint upload failed: 500 Internal Server Error - SharePoint is unavailable");
```

How can I resolve this? If you propose a fix, please make it concise.

Comment on lines +385 to +392
await expect(
getDriveItemProperties({
siteId: "site-id",
itemId: "item-id",
tokenProvider,
fetchFn: mockFetch,
}),
).rejects.toThrow("DriveItem response missing required properties");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mismatched error message

getDriveItemProperties throws "DriveItem response missing required properties (eTag, webDavUrl, or name)" when required fields are absent (extensions/msteams/src/graph-upload.ts:269-271), but this test expects "DriveItem response missing required properties". As written, the assertion won’t match the actual thrown error.

Suggested change
await expect(
getDriveItemProperties({
siteId: "site-id",
itemId: "item-id",
tokenProvider,
fetchFn: mockFetch,
}),
).rejects.toThrow("DriveItem response missing required properties");
).rejects.toThrow(
"DriveItem response missing required properties (eTag, webDavUrl, or name)",
);
Prompt To Fix With AI
This is a comment left during a code review.
Path: extensions/msteams/src/graph-upload.test.ts
Line: 385:392

Comment:
**Mismatched error message**

`getDriveItemProperties` throws `"DriveItem response missing required properties (eTag, webDavUrl, or name)"` when required fields are absent (`extensions/msteams/src/graph-upload.ts:269-271`), but this test expects `"DriveItem response missing required properties"`. As written, the assertion won’t match the actual thrown error.

```suggestion
      ).rejects.toThrow(
        "DriveItem response missing required properties (eTag, webDavUrl, or name)",
      );
```

How can I resolve this? If you propose a fix, please make it concise.

Comment on lines +451 to +458
await expect(
getChatMembers({
chatId: "chat-123",
tokenProvider,
fetchFn: mockFetch,
}),
).rejects.toThrow("Get chat members failed: 403 Forbidden");
});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing response body in assertion

getChatMembers includes the response body in its thrown error (... - ${body} at extensions/msteams/src/graph-upload.ts:296-299), but this test expects only "Get chat members failed: 403 Forbidden". With text() mocked to return "Missing Chat.Read.All permission", the error message should include that suffix.

Suggested change
await expect(
getChatMembers({
chatId: "chat-123",
tokenProvider,
fetchFn: mockFetch,
}),
).rejects.toThrow("Get chat members failed: 403 Forbidden");
});
).rejects.toThrow(
"Get chat members failed: 403 Forbidden - Missing Chat.Read.All permission",
);
Prompt To Fix With AI
This is a comment left during a code review.
Path: extensions/msteams/src/graph-upload.test.ts
Line: 451:458

Comment:
**Missing response body in assertion**

`getChatMembers` includes the response body in its thrown error (`... - ${body}` at `extensions/msteams/src/graph-upload.ts:296-299`), but this test expects only `"Get chat members failed: 403 Forbidden"`. With `text()` mocked to return `"Missing Chat.Read.All permission"`, the error message should include that suffix.

```suggestion
      ).rejects.toThrow(
        "Get chat members failed: 403 Forbidden - Missing Chat.Read.All permission",
      );
```

How can I resolve this? If you propose a fix, please make it concise.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds unit test coverage for the MS Teams graph-upload module to validate Graph upload/sharing behaviors and error handling via mocked token provider + fetch.

Changes:

  • Introduces graph-upload.test.ts with 23 Vitest cases spanning all exported functions in graph-upload.ts
  • Covers key success paths plus several validation/error scenarios (upload failures, missing response fields, per-user vs org sharing)
  • Uses injected fetchFn/token provider mocks to avoid network calls

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +295 to +299
describe("uploadToSharePoint", () => {
it("uploads a file to SharePoint site", async () => {
const tokenProvider = createMockTokenProvider();
const mockFetch = createMockFetch({
ok: true,
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The uploadToSharePoint implementation also validates that the successful JSON response includes id, webUrl, and name and throws SharePoint upload response missing required fields if any are missing (see graph-upload.ts). There isn't a unit test in this block covering that missing-fields error path; adding one (similar to the OneDrive missing-fields test) would improve coverage.

Copilot uses AI. Check for mistakes.
Comment on lines +348 to +352
describe("getDriveItemProperties", () => {
it("fetches driveItem properties for file card attachments", async () => {
const tokenProvider = createMockTokenProvider();
const mockFetch = createMockFetch({
ok: true,
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getDriveItemProperties has a !res.ok failure branch that throws Get driveItem properties failed: <status> <statusText> - <body> (see graph-upload.ts). The tests here cover success + missing properties but not the non-2xx response path; consider adding a test for a 4xx/5xx response to exercise that error handling.

Copilot uses AI. Check for mistakes.
Comment on lines +461 to +465
describe("createSharePointSharingLink", () => {
it("creates organization-scoped link using v1.0 API by default", async () => {
const tokenProvider = createMockTokenProvider();
const mockFetch = createMockFetch({
ok: true,
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

createSharePointSharingLink throws Create SharePoint sharing link response missing webUrl when the response JSON lacks link.webUrl (see graph-upload.ts). There isn't a test case in this section covering that validation error yet; adding one would complete coverage of this function’s main error branches (analogous to the OneDrive createSharingLink missing-webUrl test).

Copilot uses AI. Check for mistakes.
Addresses openclaw#8947. The '(default)' label was confusing because it didn't

clearly indicate that this agent handles incoming channel messages.

Changed to '(channel default)' for clarity in both 'agents list' and

'openclaw status' output.
@openclaw-barnacle openclaw-barnacle bot added the commands Command implementations label Feb 4, 2026
RajdeepKushwaha5 and others added 2 commits February 5, 2026 04:01
…sions

When listing sessions in status/sessions commands, prefer the current

model catalog's contextTokens over the stale cached value in sessions.json.

Fixes openclaw#8937
@openclaw-barnacle openclaw-barnacle bot added the gateway Gateway runtime label Feb 4, 2026
@RajdeepKushwaha5
Copy link
Copy Markdown
Author

Summary

Fixes #8937

When listing sessions in status/sessions commands, prefer the current model catalog's contextTokens over the stale cached value in sessions.json.

Problem

The contextTokens value from the model catalog was cached in sessions.json when a session was created. If the catalog later updated with a corrected value (e.g., after a pi-ai update or OpenClaw upgrade), the stale cached value persisted indefinitely.

Solution

When displaying session info, use lookupContextTokens(model) to get the fresh catalog value, falling back to the cached entry?.contextTokens only if the catalog doesn't have the info.

Files Changed

  • src/gateway/session-utils.ts - Gateway's session listing for status/TUI
  • src/commands/sessions.ts - CLI sessions command

Testing

  • All 29 existing tests pass
  • Formatting and linting pass

@openclaw-barnacle
Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle bot added stale Marked as stale due to inactivity and removed stale Marked as stale due to inactivity labels Feb 21, 2026
@mudrii

This comment was marked as spam.

@openclaw-barnacle
Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle bot added the stale Marked as stale due to inactivity label Mar 7, 2026
@BradGroux BradGroux self-assigned this Mar 10, 2026
@BradGroux
Copy link
Copy Markdown
Contributor

Hi @RajdeepKushwaha5 — thanks for the submission. I’m the new Microsoft Teams maintainer for OpenClaw. Please give me a day or two to work through the open Teams backlog. Also, join the Twitter community for daily MS Teams feedback + updates: https://x.com/i/communities/2031170403607974228

1 similar comment
@BradGroux
Copy link
Copy Markdown
Contributor

Hi @RajdeepKushwaha5 — thanks for the submission. I’m the new Microsoft Teams maintainer for OpenClaw. Please give me a day or two to work through the open Teams backlog. Also, join the Twitter community for daily MS Teams feedback + updates: https://x.com/i/communities/2031170403607974228

@vincentkoc
Copy link
Copy Markdown
Member

Thanks. The idea may still be valid, but this PR no longer maps cleanly to current main during the refactor. If the regression still reproduces on latest main, please open a fresh PR with current failing evidence.

@vincentkoc vincentkoc closed this Mar 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: msteams Channel integration: msteams commands Command implementations gateway Gateway runtime stale Marked as stale due to inactivity

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants