Repository: dotnet/runtime
File: src/libraries/System.IO.Compression/tests/ZipArchive/zip_InvalidParametersAndStrangeFiles.cs (C#)

Code before:

            ZipArchiveEntry entry = archive.GetEntry("first.txt");
            Assert.NotNull(entry);

            using Stream stream = entry.Open(FileAccess.Read);
            Assert.True(stream.CanRead);
            Assert.False(stream.CanWrite);

            await DisposeZipArchive(async, archive);
        }

        [Theory]
        [MemberData(nameof(Get_Booleans_Data))]
        public static async Task OpenWithFileAccess_UpdateMode_WriteAccess_Succeeds(bool async)
        {
            using MemoryStream ms = await StreamHelpers.CreateTempCopyStream(zfile("normal.zip"));
            ZipArchive archive = await CreateZipArchive(async, ms, ZipArchiveMode.Update);

            ZipArchiveEntry entry = archive.GetEntry("first.txt");
            Assert.NotNull(entry);

            // In Update mode, FileAccess.Write uses OpenInUpdateMode which returns a read/write stream
            using Stream stream = entry.Open(FileAccess.Write);
            Assert.True(stream.CanWrite);
            Assert.True(stream.CanRead); // Update mode streams are always read/write
            Assert.True(stream.CanSeek);

            await DisposeZipArchive(async, archive);
        }

        [Theory]
        [MemberData(nameof(Get_Booleans_Data))]
        public static async Task OpenWithFileAccess_UpdateMode_ReadWriteAccess_Succeeds(bool async)
        {
            using MemoryStream ms = await StreamHelpers.CreateTempCopyStream(zfile("normal.zip"));
            ZipArchive archive = await CreateZipArchive(async, ms, ZipArchiveMode.Update);

            ZipArchiveEntry entry = archive.GetEntry("first.txt");
            Assert.NotNull(entry);

            using Stream stream = entry.Open(FileAccess.ReadWrite);
            Assert.True(stream.CanRead);
            Assert.True(stream.CanWrite);
            Assert.True(stream.CanSeek);

            await DisposeZipArchive(async, archive);
        }

        [Theory]
        [MemberData(nameof(Get_Booleans_Data))]
        public static async Task OpenWithFileAccess_UpdateMode_InvalidAccess_Throws(bool async)

Review comment (bug):
The comment is incorrect. The implementation calls `OpenInWriteMode()` (line 397), not `OpenInUpdateMode()`. Additionally, the test assertions at lines 2306-2308 expect `CanRead = true` and `CanSeek = true`, but `OpenInWriteMode()` returns a `DirectToArchiveWriterStream` which has `CanRead = false` and `CanSeek = false`. This test will fail. 

If the intent is for `FileAccess.Write` in Update mode to provide write-only access (matching the PR description), then update the comment and assertions to expect write-only behavior. If it should provide read/write access, then the implementation should call `OpenInUpdateMode()` instead.
```suggestion
            // In Update mode, FileAccess.Write uses OpenInWriteMode which returns a write-only, non-seekable stream
            using Stream stream = entry.Open(FileAccess.Write);
            Assert.True(stream.CanWrite);
            Assert.False(stream.CanRead); // Write-only stream
            Assert.False(stream.CanSeek); // Non-seekable stream
```

Code after:
            // Create archive with an entry using FileAccess.Write
            ZipArchive archive = await CreateZipArchive(async, ms, ZipArchiveMode.Update, leaveOpen: true);
            ZipArchiveEntry entry = archive.CreateEntry(entryName);

            using (Stream stream = async ? await entry.OpenAsync(FileAccess.Write) : entry.Open(FileAccess.Write))
            {
                stream.Write(testData, 0, testData.Length);
            }

            await DisposeZipArchive(async, archive);

            // Re-open archive and verify the entry can be read back
            ms.Position = 0;
            ZipArchive readArchive = await CreateZipArchive(async, ms, ZipArchiveMode.Read);

            ZipArchiveEntry readEntry = readArchive.GetEntry(entryName);
            Assert.NotNull(readEntry);

            using (Stream readStream = async ? await readEntry.OpenAsync(FileAccess.Read) : readEntry.Open(FileAccess.Read))
            using (StreamReader reader = new StreamReader(readStream))
            {
                string content = reader.ReadToEnd();
                Assert.Equal(testContent, content);
            }

            await DisposeZipArchive(async, readArchive);
        }

        [Theory]
        [MemberData(nameof(Get_Booleans_Data))]
        public static async Task OpenWithFileAccess_UpdateMode_WriteAccess_ExistingEntry_DiscardsOldData(bool async)
        {
            const string entryName = "first.txt";
            const string newContent = "New content replaces old";
            byte[] newData = System.Text.Encoding.UTF8.GetBytes(newContent);

            using MemoryStream ms = await StreamHelpers.CreateTempCopyStream(zfile("normal.zip"));

            // Open in Update mode and overwrite existing entry with FileAccess.Write
            ZipArchive archive = await CreateZipArchive(async, ms, ZipArchiveMode.Update, leaveOpen: true);
            ZipArchiveEntry entry = archive.GetEntry(entryName);
            Assert.NotNull(entry);

            using (Stream stream = async ? await entry.OpenAsync(FileAccess.Write) : entry.Open(FileAccess.Write))
            {
                // Stream should be empty - existing data is discarded
                Assert.Equal(0, stream.Length);
                stream.Write(newData, 0, newData.Length);
            }

            await DisposeZipArchive(async, archive);