-
Notifications
You must be signed in to change notification settings - Fork 24
Fix publish/setup docs and Node Oryx TypeScript deploy behavior #318
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
ITSpecialist111
wants to merge
5
commits into
microsoft:main
from
ITSpecialist111:fix/deploy-publish-docs-and-nodebuild-typescript
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e87b7e7
Fix publish/setup docs and Node Oryx TypeScript deploy behavior
ITSpecialist111 cbcc69f
fix: address code review feedback for PR #318
sellakumaran 80a1a81
fix: address Copilot PR review comments for PR #318
sellakumaran 0a1b734
chore: merge main into PR branch and resolve CHANGELOG.md conflict
sellakumaran e348ec4
fix: address review comments on a365-setup-instructions.md
sellakumaran File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
139 changes: 139 additions & 0 deletions
139
src/Tests/Microsoft.Agents.A365.DevTools.Cli.Tests/Services/NodeBuilderTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,139 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using FluentAssertions; | ||
| using Microsoft.Agents.A365.DevTools.Cli.Services; | ||
| using Microsoft.Extensions.Logging; | ||
| using NSubstitute; | ||
|
|
||
| namespace Microsoft.Agents.A365.DevTools.Cli.Tests.Services; | ||
|
|
||
| public class NodeBuilderTests : IDisposable | ||
| { | ||
| private readonly ILogger<NodeBuilder> _logger; | ||
| private readonly NodeBuilder _builder; | ||
| private readonly List<string> _tempDirectories; | ||
|
|
||
| public NodeBuilderTests() | ||
| { | ||
| _logger = Substitute.For<ILogger<NodeBuilder>>(); | ||
| var executorLogger = Substitute.For<ILogger<CommandExecutor>>(); | ||
| var mockExecutor = Substitute.ForPartsOf<CommandExecutor>(executorLogger); | ||
| _builder = new NodeBuilder(_logger, mockExecutor); | ||
| _tempDirectories = new List<string>(); | ||
| } | ||
|
|
||
| public void Dispose() | ||
| { | ||
| foreach (var dir in _tempDirectories) | ||
| { | ||
| if (Directory.Exists(dir)) | ||
| Directory.Delete(dir, recursive: true); | ||
| } | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task CreateManifestAsync_TypeScriptProjectWithDistFolder_SkipsOryxBuild() | ||
| { | ||
| // Arrange | ||
| var projectDir = CreateTempDirectory(); | ||
| var publishPath = CreateTempDirectory(); | ||
|
|
||
| WritePackageJson(projectDir, buildScript: "tsc", startScript: "node dist/index.js"); | ||
| File.WriteAllText(Path.Combine(projectDir, "tsconfig.json"), "{}"); | ||
| Directory.CreateDirectory(Path.Combine(publishPath, "dist")); | ||
|
|
||
| // Act | ||
| var manifest = await _builder.CreateManifestAsync(projectDir, publishPath); | ||
|
|
||
| // Assert | ||
| manifest.BuildRequired.Should().BeFalse( | ||
| because: "when dist/ exists and tsconfig.json is present, TypeScript was compiled locally " + | ||
| "and Oryx must not re-run npm run build — Oryx's production install skips devDependencies " + | ||
| "so tsc would not be found, causing deployment failure"); | ||
| manifest.BuildCommand.Should().BeEmpty( | ||
| because: "no build command should be set when the Oryx remote build is skipped"); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task CreateManifestAsync_TypeScriptProjectWithoutDistFolder_UsesOryxBuild() | ||
| { | ||
| // Arrange | ||
| var projectDir = CreateTempDirectory(); | ||
| var publishPath = CreateTempDirectory(); | ||
|
|
||
| WritePackageJson(projectDir, buildScript: "tsc", startScript: "node dist/index.js"); | ||
| File.WriteAllText(Path.Combine(projectDir, "tsconfig.json"), "{}"); | ||
| // No dist/ in publish output — TypeScript not yet compiled | ||
|
|
||
| // Act | ||
| var manifest = await _builder.CreateManifestAsync(projectDir, publishPath); | ||
|
|
||
| // Assert | ||
| manifest.BuildRequired.Should().BeTrue( | ||
| because: "when dist/ is absent the TypeScript project was not pre-compiled so Oryx must run npm run build"); | ||
| manifest.BuildCommand.Should().Be("npm run build"); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task CreateManifestAsync_JavaScriptProjectWithDistFolder_UsesOryxBuild() | ||
| { | ||
| // Arrange | ||
| var projectDir = CreateTempDirectory(); | ||
| var publishPath = CreateTempDirectory(); | ||
|
|
||
| WritePackageJson(projectDir, buildScript: "webpack", startScript: "node dist/bundle.js"); | ||
| // No tsconfig.json — JavaScript-only project with webpack producing dist/ | ||
| Directory.CreateDirectory(Path.Combine(publishPath, "dist")); | ||
|
|
||
| // Act | ||
| var manifest = await _builder.CreateManifestAsync(projectDir, publishPath); | ||
|
|
||
| // Assert | ||
| manifest.BuildRequired.Should().BeTrue( | ||
| because: "JavaScript-only projects without tsconfig.json should still use Oryx remote build " + | ||
| "even when dist/ exists — skipping would be incorrect since the build script produces the bundle"); | ||
| manifest.BuildCommand.Should().Be("npm run build"); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task CreateManifestAsync_WithoutBuildScript_DoesNotSetBuildRequired() | ||
| { | ||
| // Arrange | ||
| var projectDir = CreateTempDirectory(); | ||
| var publishPath = CreateTempDirectory(); | ||
|
|
||
| WritePackageJson(projectDir, buildScript: null, startScript: "node server.js"); | ||
|
|
||
| // Act | ||
| var manifest = await _builder.CreateManifestAsync(projectDir, publishPath); | ||
|
|
||
| // Assert | ||
| manifest.BuildRequired.Should().BeFalse( | ||
| because: "no build script in package.json means Oryx only runs npm install, not a build step"); | ||
| manifest.BuildCommand.Should().BeEmpty(); | ||
| } | ||
|
|
||
| private static void WritePackageJson(string projectDir, string? buildScript, string startScript) | ||
| { | ||
| var scripts = buildScript is not null | ||
| ? $@"""build"": ""{buildScript}"", ""start"": ""{startScript}""" | ||
| : $@"""start"": ""{startScript}"""; | ||
|
|
||
| File.WriteAllText(Path.Combine(projectDir, "package.json"), $$""" | ||
| { | ||
| "scripts": { | ||
| {{scripts}} | ||
| } | ||
| } | ||
| """); | ||
| } | ||
|
|
||
| private string CreateTempDirectory() | ||
| { | ||
| var dir = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); | ||
| Directory.CreateDirectory(dir); | ||
| _tempDirectories.Add(dir); | ||
| return dir; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.